• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

No suitable driver error when configuring JDBC datasource for Tomcat and Struts

 
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I know many people encountered this problem before, but I still couldn't figure it out... I got this error when configuring JDBC datasource for Tomcat and Struts:

Exception: org.apache.commons.dbcp.SQLNestedException: Cannot create JDBC driver of class '' for connect URL 'null', cause: No suitable driver

Please note that the class is empty and connect URL is null, but I did supply the necessary info in my server.xml file based on the instructions on Apache website, and my JDBC driver is under tomcat/commin/lib directory.

Here's my server.xml file: I configure JDBC datasource as a Global resource for JNDI lookup:

<code>
<GlobalNamingResources>
<Resource name="jdbc/oracle" auth="Container" type="javax.sql.DataSource"
description="Oracle database connection" >
</Resource>
<ResourceParams name="jdbc/oracle">
<Parameter>
<name>factory</name>
<value>org.apache.commons.dbcp.BasicDataSourceFactory</value>
</Parameter>
<Parameter>
<name>driverClassName</name>
<value>oracle.jdbc.driver.OracleDriver</value>
</Parameter>
<Parameter>
<name>url</name>
<value>jdbc racle:thin:@<server URL>:1521:<SID></value>
</Parameter>
<Parameter>
<name>username</name>
<value>****</value>
</Parameter>
<Parameter>
<name>password</name>
<value>****</value>
</Parameter>
</ResourceParams>
</code>

My web.xml:<code>
<resource-ref>
<description>DB Connection Pool</description>
<res-ref-name>jdbc/oracle</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref></code>

I didn't put any extra info about the resource in my context.xml file, except default configuation. Shall I put anything in the file to associate the global resource for my context? Doesn't gloabl resource automcatically available to all contexts?

Another question is: Both Tomcat and Struts allow us to configure datasource in the config file. Where is the better place to handle this: server.xml for Tomcat or struts-config.xml? Is there any performance difference among the 2, even if both configuration use the same datasource class. (I chose to use Tomcat because it seems Struts now only allow us to get DataSource from Action class, and I need JDBC datasource for application service initialization. Or is there other ways to get datasource from Struts? findDataSource is deprecated.)

Please help me with these problems. Any help is highly appreciated!!!
[ June 04, 2004: Message edited by: JW Li ]
 
JW Li
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I've found how to fix this problem. At least in my case:

1. First, I couldn't really explain how Tomcat didn't get the correct driver class name and URL at first, but after I tried to type in some error values on purpose, and change it back, it suddenly works (i.e. at least the server output printed out the correct driver class name and URL I put in the server.xml file. Sorry, I couldn't give a more reasonable explanation on how this has been fixed in my case...

2. the URL connect string should include schema, like this:
jdbc racle:thin:<schema>@<server URL>:1521:<SID>
It seems that if the driver is not happy with this URL, then it will also give the No suitable driver error message.

3. Put a resource link in the context:
<Context...>
<ResourceLink name=<> global=<> />
.....

I hope this can help those who are also struggled to solve this configuration problem. Thanks!
 
Ranch Hand
Posts: 69
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Li,

I also come accross the same problem.

The solution you have given in not very clear.

Can you clarify please.
Thanks,
Bhuvana
 
JW Li
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

Basically the problem went away (at least for me) with these 2 fixes:

1. Make sure you have schema in the url string to connect to database:

jdbc:oracle:thin:<schema>@<server>:<port>:<sid>

2. Since I defined my database resource as a global resource in server.xml file, I need an extra parameter in the corresponding context:

<ResourceLink name="<database resource name as defined in GlobalResources>"
global="<same as above name>" />

I still don't know why I need this extra line, 'cause I thought Global resources will be automatically available for all contexts...

These work for me for this problem! BTW, I ended up initializing my database resources by my own class, since even though I got through this problem, and successfully get a DataSource back, when I tried to use the dataSource to getConnection, I always got a null pointer exception coming from DBCP's internal code... I've tired of fighting with this configuration problem, so I follow the example code in DBCP website to configure the database pooling, and it worked! Anyway, Good luck to you!
 
reply
    Bookmark Topic Watch Topic
  • New Topic