File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Struts and the fly likes No suitable driver error when configuring JDBC datasource for Tomcat and Struts Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "No suitable driver error when configuring JDBC datasource for Tomcat and Struts" Watch "No suitable driver error when configuring JDBC datasource for Tomcat and Struts" New topic
Author

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

JW Li
Ranch Hand

Joined: Mar 11, 2003
Posts: 33
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

Joined: Mar 11, 2003
Posts: 33
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!
Boon Subra
Ranch Hand

Joined: Jul 18, 2001
Posts: 69
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

Joined: Mar 11, 2003
Posts: 33
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:

jdbcracle: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!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: No suitable driver error when configuring JDBC datasource for Tomcat and Struts