This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Tomcat and the fly likes Configuring a MySQL DataSource in Tomcat5 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Products » Tomcat
Bookmark "Configuring a MySQL DataSource in Tomcat5" Watch "Configuring a MySQL DataSource in Tomcat5" New topic

Configuring a MySQL DataSource in Tomcat5

Edward Kenworthy
Ranch Hand

Joined: Oct 05, 2003
Posts: 66
I'm trying to configure a DataSource but I'm getting this exception:

java.sql.SQLException: Cannot load JDBC driver class 'null'
info.kenworthy.reqxml.webapp.servlets.ManageProjects.doGet(Unknown Source)
info.kenworthy.reqxml.webapp.servlets.Controller.doGet(Unknown Source)

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:

<description>DB Connection</description>

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"

<Resource name="jdbc/ReqXMLDB"

<ResourceParams name="jdbc/ReqXML">

<!-- 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.


<!-- Maximum number of idle dB connections to retain in pool.
Set to 0 for no limit.

<!-- 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.

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


<!-- Class name for the official MySQL Connector/J driver -->

<!-- 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.

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

Mike Curwen
Ranch Hand

Joined: Feb 20, 2001
Posts: 3695

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

Joined: Oct 05, 2003
Posts: 66
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 ( version after a re-deploy. Both these errors are intermittent: Restarting (and sometimes even re-booting my Mac!) is required to fix it.

I agree. Here's the link:
subject: Configuring a MySQL DataSource in Tomcat5
Similar Threads
DBCP Null pointer exception
~~ Newbie question - database ~~
Help With Connection Pool
connection pooling problem
Cannot create JDBC driver of class '' for connect URL 'null',