Java Mailing List Archive

http://www.junlu.com/

Home » Home (12/2007) » Apache Tomcat »

6.0.13 MySQL DBCP Example

G M

2007-08-08

Replies:

I've been trying for days now to establish a jdbc resource for mysql in
tomcat 6.0.13

To whom it may correspond:

I get the following error

Unable to get connection, DataSource invalid:
"org.apache.tomcat.dbcp.dbcp.SQLNestedException
: Cannot create JDBC driver of class '' for connect URL 'null'"


I have the driver mysql-connector-java-5.0.6-bin.jar copied to
$CATALINA_HOME/lib

My application web.xml looks like this: (exactly as the example)

<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance "
  xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd "
  version="2.4">
<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>
</web-app>

In
http://tomcat.apache.org/tomcat-6.0-doc/jndi-datasource-examples-howto.htmlthere
is this instruction:

Add this in between the </Context> tag of the examples context and the
> </Host> tag closing the localhost definition. If there is no such tag, you
> can add one as illustrated in the Context<http://tomcat.apache.org/tomcat-6.0-doc/config/context.html>and
> Host <http://tomcat.apache.org/tomcat-6.0-doc/config/host.html>configuration references, and repeated below for your convenience.


In my own opinion this is quite ambiguous. After several search in the mail
repositories. I have this as my server.xml configuration (i deleted the
comments for easy reading)

<Server port="8005" shutdown="SHUTDOWN">
<Listener className="org.apache.catalina.core.AprLifecycleListener"
SSLEngine="on" />
<Listener className="org.apache.catalina.core.JasperListener" />
<Listener className="org.apache.catalina.mbeans.ServerLifecycleListener"
/>
<Listener className="
org.apache.catalina.mbeans.GlobalResourcesLifecycleListener" />

<GlobalNamingResources>
  <Resource name="UserDatabase" auth="Container"
        type="org.apache.catalina.UserDatabase"
        description="User database that can be updated and saved"
        factory="org.apache.catalina.users.MemoryUserDatabaseFactory"
        pathname="conf/tomcat-users.xml" />
</GlobalNamingResources>

<Service name="Catalina">

  <Connector port="8080" protocol="HTTP/1.1"
         connectionTimeout="20000"
         redirectPort="8443" />
  <Connector port="8009" protocol="AJP/1.3" redirectPort="8443" />
  <Engine name="Catalina" defaultHost="localhost">

   <Realm className="org.apache.catalina.realm.UserDatabaseRealm"
        resourceName="UserDatabase"/>

   <Host name="localhost" appBase="webapps"
       unpackWARs="true" autoDeploy="true"
       xmlValidation="false" xmlNamespaceAware="false">

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


       <Resource name="jdbc/TestDB" auth="Container" type="
javax.sql.DataSource"
         maxActive="100" maxIdle="30" maxWait="10000"
         username="gabo" password="huevos" driverClassName="
com.mysql.jdbc.Driver "

url="jdbc:mysql://localhost:3306/javatest?autoReconnect=true"/>

    </Context>
   </Host>
  </Engine>
</Service>
</Server>

In my own opinion the problem is with server.xml, should I add something to
context.xml?
Any comment, hint or tip would be greatly appreciated.

Regards

Gabriel
©2008 junlu.com - Jax Systems, LLC, U.S.A.