tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From NBW <email...@gmail.com>
Subject Problem configuring JDBC DataSource Tomcat 5.5.23 / MySQL 5.0
Date Thu, 08 Nov 2007 18:07:25 GMT
Hi, I'm having difficulty configuring a container managed JDBC
resource. I've read several posts in the tomcat-users archives
(discussing similar issues) as well as the documentation at:

http://tomcat.apache.org/tomcat-5.5-doc/jndi-resources-howto.html

My environments looks like this:

Tomcat 5.5.23 (Windows XP)
MySQL 5.0.45
MySQL Connector/J 5.1.5
JDK 1.6.0_02

My context.xml is deployed in %TOMCAT_HOME%/webapps/myApp/META-INF and
contains the following:

<?xml version="1.0" encoding="UTF-8"?>
<Context path="/myApp" docBase="myApp" debug="5" reloadable="true"
crossContext="true">

    <Resource name="jdbc/MyDB" auth="Container"
type="javax.sql.DataSource" maxActive="100" maxIdle="30"
              maxWait="10000" username="mydbuser" password="mydbuser"
driverClassName="com.mysql.jdbc.Driver"
              validationQuery="/* ping */" logAbandoned="true"
removeAbandoned="true" removeAbandonedTimeout="60"
              url="jdbc:mysql://localhost:3306/myApp_db1"/>

</Context>

My web.xml file is located in %TOMCAT_HOME%/webapps/myApp/WEB-INF and
contains among other things the following:

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.4"
         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" >

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

...
</web-app>

The MySQL driver JAR is deployed in %TOMCAT_HOME%/webapps/myApp/WEB-INF/lib

Finally, my code trying to load the resource is the following:

            Context initCtx = new InitialContext();
            Context envCtx = (Context) initCtx.lookup("java:comp/env");
            DataSource myDataSource = (DataSource) envCtx.lookup("jdbc/MyDB");

When I deploy and run I am getting the following exception:

2007-11-08 12:41:31,593 [Thread-1] ERROR Unable get a SQL connection:
org.apache.tomcat.dbcp.dbcp.SQLNestedException: Cannot create JDBC
driver of class '' for connect URL 'null'
	at org.apache.tomcat.dbcp.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:780)
	at org.apache.tomcat.dbcp.dbcp.BasicDataSource.getConnection(BasicDataSource.java:540)
	[SNIP]
	at com.myApp.InitServlet.init(InitServlet.java:56)
	at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1139)
	at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:966)
	at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:3956)
	at org.apache.catalina.core.StandardContext.start(StandardContext.java:4230)
	at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:760)
	at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:740)
	at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:544)
	at org.apache.catalina.startup.HostConfig.deployDescriptor(HostConfig.java:626)
	at org.apache.catalina.startup.HostConfig.deployDescriptors(HostConfig.java:553)
	at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:488)
	at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1138)
	at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:311)
	at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:120)
	at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1022)
	at org.apache.catalina.core.StandardHost.start(StandardHost.java:736)
	at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1014)
	at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:443)
	at org.apache.catalina.core.StandardService.start(StandardService.java:448)
	at org.apache.catalina.core.StandardServer.start(StandardServer.java:700)
	at org.apache.catalina.startup.Catalina.start(Catalina.java:552)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
	at java.lang.reflect.Method.invoke(Method.java:597)
	at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:295)
	at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:433)
Caused by: java.lang.NullPointerException
	at sun.jdbc.odbc.JdbcOdbcDriver.getProtocol(JdbcOdbcDriver.java:507)
	at sun.jdbc.odbc.JdbcOdbcDriver.knownURL(JdbcOdbcDriver.java:476)
	at sun.jdbc.odbc.JdbcOdbcDriver.acceptsURL(JdbcOdbcDriver.java:307)
	at java.sql.DriverManager.getDriver(DriverManager.java:253)
	at org.apache.tomcat.dbcp.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:773)
	... 36 more

What is interesting is when I look at Catalina's MBeans using JConsole
I can see the following DataSource /myApp - localhost -
javax.sql.DataSource "jdbc/MyDB" but most of its attributes are empty
(eg. username, url, password) and the ones which do have values such
as maxIdle have defauls (eg. maxIdle is set to 8) whereas my context
Resource sets it to 30.

I've been over and over the config. and don't see where I am doing
anything different then the documentation suggests.  Does anyone have
any advice?

TIA.

-NBW

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Mime
View raw message