Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Database connection pool in Tomcat 5: doesn't work out

Status
Not open for further replies.

correro

Programmer
Nov 20, 2003
54
0
0
CN
I'm using Tomcat 5 as web container. I followed the instructions (strictly and exactly) in JNDI Datasource HOW-TO to create database connection pool. But I keep getting this exception:

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

While it works fine if I create a Connection using DriverManager.

Can you tell someone tell me what is wrong?
 
Do you have the JDBC driver in common/lib directory of Tomcat?
 
yes, i put the jar file containing the JDBC driver in <CATALINA_HOME>/common/lib

everything was done according to the HOW-TO
 
&quot;org.apache.commons.dbcp.SQLNestedException: Cannot create JDBC driver of class '' for connect URL 'null'...&quot;

Seem like the datasource is not setup correctly, there is no driver class or connection URL defined.

Are you able to see the setting in the Tomcat admin interface?
 
I tried setting up the DBCP in two ways:

(1) manually as instructed in Tomcat 5 JNDI Datasource HOW-TO

(2) using Tomcat admin interface

Both ways, I get the same exception: Cannot create JDBC driver of class '' for connect URL 'null'

Seems that the JDBC driver class name was not passed to the container. I don't know why.

Please note that the same database can be accessed when I create a Connection using a DriverManager.
 
<Server>
... ...
<GlobalNamingResources>
... ...
<ResourceParams name=&quot;jdbc/TestDB&quot;>
<parameter>
<name>maxWait</name>
<value>5000</value>
</parameter>
<parameter>
<name>maxActive</name>
<value>4</value>
</parameter>
<parameter>
<name>password</name>
<value>javadude</value>
</parameter>
<parameter>
<name>url</name>
<value>jdbc:mysql://localhost:3306/javatest?autoReconnect=true</value>
</parameter>
<parameter>
<name>driverClassName</name>
<value>org.gjt.mm.mysql.Driver</value>
</parameter>
<parameter>
<name>maxIdle</name>
<value>2</value>
</parameter>
<parameter>
<name>username</name>
<value>javauser</value>
</parameter>
</ResourceParams>
</GlobalNamingResources>
... ...
</Server>

============================
This is the server.xml, automatically generated by Tomcat Admin. I don't see there is anything wrong with it.

Please help me diagnose it. Thanks!
 
This seems to be a bug with the Tomcat 5.016. You may have success by putting the contents of <ResourceParams name=&quot;jdbc/TestDB&quot;> in the specific default xml config file for that webapp. That shouild be located in $CATALINA_HOME/Catalina/localhost/yourapp.xml

remove any other <Resource> definitions pertaining to this db connection there may be in there created by the admin app.

good luck
Sanjay
 
Hi,

I am getting the same error and I am using:==
Please help !!

-- Apache Tomcat/4.1.29
-- SQL*Plus: Release 9.0.1.4.0 - Oracle8i Enterprise Edition Release 8.1.6.0.0
-- j2sdk1.4.2_03
-- ojdbc14.jar

Regards
Abhay
 
Thanks netitects. This fixed hours of frustration for me. I just copied the entry created by the admin app in server.xml between the ResourceName to /ResourceParams and put it into the application xml file under localhost. I also then deleted the entry using the admin app from server.xml. I previously was getting the error message org.apache.commons.dbcp.SQLNestedException: Cannot create JDBC driver of class ' ' for connect URL 'null', cause: java.sql.SQLException: No suitable driver.
 
I think I've figured out what caused the error.

You'd need to put <Resource> and <ResourceParams> in the proper <Context>

It doesn't seem to work when you put them in <GlobalNamingResources>
 
netitects was right. It works when you put <ResourceParams> in $CATALINA_HOME/Catalina/localhost/yourapp.xml. It also works when you put them within <Context path=&quot;/yourapp&quot;...> in server.xml
 
I've been experiencing a similar problem. I use tomcat 4.1.18 and I have DBCP working well on my windows (development) machine.
However, when I port the server.xml file over to my production server (running Linux) I get the
&quot;Cannot create JDBC driver of class '' for connect URL 'null'&quot; error.

I have the <Resource> and <ResourceParams> tags nested in my specific <Context>, but it only works on my Windows machine.

It's as though the <Resource> and <ResourceParams> tags aren't being recognized.

Any thoughts?

 
This usually is caused either by a missing resource reference in the /WEB-INF/web.xml file of your app or a discrepancy in your context path of the app and the path the datasource was defined in.
Based on the server.xml file above you need to correct the following:
<resource-ref>
<description>universal connection</description>
<res-ref-name>universal</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>


and make sure you are access in the app at /closesuitejsp

netitects.com


 
Being hard headed, I persevered and was able to get this to work within <GlobalNamingResources>. I think there is some kind of issue when the default $CATALINA_HOME/Catalina/localhost/yourapp.xml file is created from the context.xml (found in the actual webapp deployment).

If you were like me and followed Sun's recommendations on setting up linkages, you put this in your context.xml file:

Code:
<Context path="/appdir" docBase="appdir" debug="0">
  <ResourceLink name="jdbc/dbName" global="dbName" />   
</Context>

Note this uses a relative directory for docBase because this is being deployed in a production system using a .war file and the full directory structure isn't known. Now it appears that, at least for me, Tomcat converted this into the following yourapp.xml file when it went about filling in the system specific information:

Code:
<?xml version='1.0' encoding='utf-8'?>
<Context displayName="appName" docBase="D:\someGlobalPathStuff\appdir" path="/appdir"
         workDir="work\Catalina\localhost\appdir">
  <Resource auth="Container" name="jdbc/dbName" type="javax.sql.DataSource"/>
</Context>

Notice the <Resource ...> line. This does not work. Hmmm, as far as I could tell, it should have been this:

Code:
  <ResourceLink auth="Container" name="jdbc/dbName" global="dbName"
                type="javax.sql.DataSource"/>

Sure enough, change the <Resource ...> line to <ResourceLink global="dbName" ...> in yourapp.xml and it works.

For completeness, this was found on the following production Windows NT system:

[tt]
Tomcat V5.0.28
j2sdk1.4.1_01
mysql V4.0.18
[/tt]

and the following was in the web.xml file for the app:

Code:
    <resource-ref>
        <res-ref-name>jdbc/dbName</res-ref-name>
        <res-type>javax.sql.DataSource</res-type>
        <res-auth>Container</res-auth>
        <res-sharing-scope>Shareable</res-sharing-scope>
    </resource-ref>

Hope this helps.
 
reallyblurredvision, i'm very interested in your solution, but didn't work it out myself.

Can you please be more specific about how to modify server.xml, web.xml, or whatever? Tell me what tags and what lines to add/remove in what file. Thanks!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top