This week's book giveaway is in the OCMJEA forum. We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line! See this thread for details.
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:
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 ]
Joined: Mar 11, 2003
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!
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:
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!