• 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:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

Configuring a MySQL DataSource in Tomcat5

 
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm trying to configure a DataSource but I'm getting this exception:

java.sql.SQLException: Cannot load JDBC driver class 'null'
org.apache.commons.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:529)
org.apache.commons.dbcp.BasicDataSource.getConnection(BasicDataSource.java:312)
info.kenworthy.reqxml.webapp.servlets.ManageProjects.doGet(Unknown Source)
javax.servlet.http.HttpServlet.service(HttpServlet.java:743)
javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
info.kenworthy.reqxml.webapp.servlets.Controller.doGet(Unknown Source)
javax.servlet.http.HttpServlet.service(HttpServlet.java:743)
javax.servlet.http.HttpServlet.service(HttpServlet.java:856)

Which is thrown by this bit of code in my Servlet:

conn = _pool.getConnection();

I have the DS resource configured in my web.xml like this:


<resource-ref>
<description>DB Connection</description>
<res-ref-name>jdbc/ReqXMLDB</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>

And in the Tomcat server.xml inside the localhost <Host> like this:

<Context path="/ReqXML" docBase="ReqXML"
debug="5" reloadable="true" crossContext="true">

<Logger className="org.apache.catalina.logger.FileLogger"
prefix="localhost_DBTest_log." suffix=".txt"
timestamp="true"/>

<Resource name="jdbc/ReqXMLDB"
auth="Container"
type="javax.sql.DataSource"/>

<ResourceParams name="jdbc/ReqXML">
<parameter>
<name>factory</name>
<value>org.apache.commons.dbcp.BasicDataSourceFactory</value>
</parameter>

<!-- Maximum number of dB connections in pool. Make sure you
configure your mysqld max_connections large enough to handle
all of your db connections. Set to 0 for no limit.
-->

<parameter>
<name>maxActive</name>
<value>100</value>
</parameter>

<!-- Maximum number of idle dB connections to retain in pool.
Set to 0 for no limit.
-->
<parameter>
<name>maxIdle</name>
<value>30</value>
</parameter>

<!-- Maximum time to wait for a dB connection to become available
in ms, in this example 10 seconds. An Exception is thrown if
this timeout is exceeded. Set to -1 to wait indefinitely.
-->
<parameter>
<name>maxWait</name>
<value>10000</value>
</parameter>

<!-- MySQL dB username and password for dB connections -->

<parameter>
<name>username</name>
<value>reqxml</value>
</parameter>
<parameter>
<name>password</name>
<value>reqxml</value>
</parameter>

<!-- Class name for the official MySQL Connector/J driver -->
<parameter>
<name>driverClassName</name>
<value>com.mysql.jdbc.Driver</value>
</parameter>

<!-- The JDBC connection url for connecting to your MySQL dB.
The autoReconnect=true argument to the url makes sure that the
mm.mysql JDBC Driver will automatically reconnect if mysqld closed the
connection. mysqld by default closes idle connections after 8 hours.
-->
<parameter>
<name>url</name>
<value>jdbc:mysql://localhost:3306/reqxml?autoReconnect=true</value>
</parameter>
</ResourceParams>
</Context>

And I've copied mysql-connector-java-3.0.14-production-bin.jar into my Tomcat common/lib directory.

Help!
 
Ranch Hand
Posts: 3695
IntelliJ IDE Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
the filename you mention, mysql-connector-java-3.0.14-production-bin.jar sounds like a download jar? If you open this file, do you see another connectorj jar file inside of it? If so, then you'll need to extract it into common/lib (and remove the parent jar).

err... but more likely:

The names don't match.
[ June 02, 2004: Message edited by: Mike Curwen ]
 
Edward Kenworthy
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
OK looks like the problem is a bug in Tomcat. I haven't been able to nail it down completely but basically once you have configured a DataSource you *must* restart Tomcat everytime you re-deploy a WebApp that uses that DataSource- simple undeploying then deploying using the Tomcat ant tasks doesn't work.

This seems to be part of a general problem with Tomcat 5 not undeploying/deploying WebApps properly. I've had similar problems with jsp files where it "find" the jsp but then can't fine the translated (xxx_jsp.java) version after a re-deploy. Both these errors are intermittent: Restarting (and sometimes even re-booting my Mac!) is required to fix it.

Edward
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic