You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Ilja <im...@hotmail.com> on 2003/09/15 11:37:15 UTC

Tomcat, MySQL & JNDI: java.sql.SQLException: Cannot load JDBC driver class 'null'

Ok, first some configuration information:

Tomcat 5.09
MySQL Driver 3.08 stable
OS: Mac OSX 10.2.6
J2SE 1.4.2

all commons libraries reside in $CATALINA_HOME/common/lib
MySQL Driver resides in $CATALINA_HOME/common/lib as well

I tried setting up a simple JNDI datasource connection but get the  
following error message:

java.sql.SQLException: Cannot load JDBC driver class 'null'
	at  
org.apache.commons.dbcp.BasicDataSource.createDataSource(BasicDataSource 
.java:529)
	at  
org.apache.commons.dbcp.BasicDataSource.getConnection(BasicDataSource.ja 
va:312)
	at foo.DBTest.init(DBTest.java:24)
	at foo.TestServlet.doGet(TestServlet.java:34)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:740)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
          ....
          ....

The code and examples are taken from  
http://jakarta.apache.org/tomcat/tomcat-5.0-doc/jndi-datasource- 
examples-howto.html

I have searched through tons of archives and websites and mostly this  
error could be resolved by placing the driver and commons in the  
common/lib directory. However in my case they are there, so I cannot  
figure out what's the problem...

server.xml:

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

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

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

  <ResourceParams name="jdbc/TestDB">
   <parameter>
    <name>driverClassName</name>
    <value>org.gjt.mm.mysql.Driver</value>
   </parameter>
   <parameter>
    <name>username</name>
    <value>xxx</value>
   </parameter>
   <parameter>
    <name>password</name>
    <value>xxx</value>
   </parameter>
   <parameter>
    <name>url</name>
    <value>jdbc:mysql://localhost/javatest?autoReconnect=true</value>
   </parameter>
  </ResourceParams>
</Context>

web.xml

<?xml version="1.0" encoding="ISO-8859-1"?>
     <!DOCTYPE web-app PUBLIC
     "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
     "http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>
   <description>MySQL Test App</description>
   <resource-ref>
       <description>DB Connection</description>
       <res-ref-name>jdbc/TestDB</res-ref-name>
       <res-type>javax.sql.DataSource</res-type>
       <res-auth>Container</res-auth>
   </resource-ref>

   <servlet>
       <servlet-name>DBTestServlet</servlet-name>
       <description>
         Bla...
       </description>
       <servlet-class>foo.TestServlet</servlet-class>
   </servlet>

   <servlet-mapping>
       <servlet-name>DBTestServlet</servlet-name>
       <url-pattern>/DBTestServlet</url-pattern>
   </servlet-mapping>
</web-app>


Re: Tomcat, MySQL & JNDI: java.sql.SQLException: Cannot load JDBC driver class 'null'

Posted by Martin Jacobson <ma...@libero.it>.
Ilja wrote:
> Ok, first some configuration information:
> 
> Tomcat 5.09
> MySQL Driver 3.08 stable
> OS: Mac OSX 10.2.6
> J2SE 1.4.2
> 

My config is not the same (TC 4.1.24, OSX 10.2.6, MySQL 3.07), and my 
parameters are different:
	<ResourceParams name="jdbc/EuratomDB">
		<parameter>
			<name>factory</name>
			<value>org.apache.commons.dbcp.BasicDataSourceFactory</value>
		</parameter>
		<parameter>
			<name>maxActive</name>
			<value>100</value>
		</parameter>
		<parameter>
			<name>maxIdle</name>
			<value>30000</value>
		</parameter>
		<parameter>
			<name>maxWait</name>
			<value>100</value>
		</parameter>
		<parameter>
			<name>username</name>
			<value>xxx</value>
		</parameter>
		<parameter>
			<name>password</name>
			<value>xxx</value>
		</parameter>
		<parameter>
			<name>driverClassName</name>
			<value>com.mysql.jdbc.Driver</value>
		</parameter>
		<parameter>
			<name>url</name>
			<value>jdbc:mysql://localhost/euratom?autoReconnect=true</value>
		</parameter>
	</ResourceParams>

This works for me! The main diffs are (i) I specify the <factory>, and 
(ii), the driverClassName is com.mysql.jdbc.Driver

However, the exception seems to suggest that the correct factory is 
being used by default. Your driverClassName is the old name, and might 
not be in the jar file any more.

HTH
Martin