The MySQL driver is in $TOMCAT_HOME/lib, but I don't think that is even the issue here -- the real problem is that the DataSource object is not initialized, so it doesn't even have the url, driver class name, etc.
This is what my log looks like when I restart Tomcat:

Dec 7, 2007 1:18:50 PM org.apache.catalina.core.AprLifecycleListener init
INFO: The Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: /home/tokken/software/jdk1.5.0_11/bin:/home/tokken/apache-tomcat-6.0.14/bin
Dec 7, 2007 1:18:51 PM org.apache.coyote.http11.Http11Protocol init
INFO: Initializing Coyote HTTP/1.1 on http-8888
Dec 7, 2007 1:18:51 PM org.apache.catalina.startup.Catalina load
INFO: Initialization processed in 729 ms
Dec 7, 2007 1:18:51 PM org.apache.catalina.core.StandardService start
INFO: Starting service Catalina
Dec 7, 2007 1:18:51 PM org.apache.catalina.core.StandardEngine start
INFO: Starting Servlet Engine: Apache Tomcat/6.0.14
Dec 7, 2007 1:18:51 PM org.apache.catalina.startup.HostConfig deployDescriptor WARNING: A docBase /home/tokken/apache-tomcat-6.0.14/webapps/smm inside the host appBase has been specified, and will be ignored
Dec 7, 2007 1:18:52 PM org.apache.struts.action.ActionServlet initChain
INFO: Loading chain catalog from jar:file:/home/tokken/apache-tomcat-6.0.14/webapps/smm/WEB-INF/lib/struts-core-1.3.8.jar!/org/apache/struts/chain/chain-config.xml
Dec 7, 2007 1:18:53 PM org.apache.catalina.startup.HostConfig deployWAR
INFO: Deploying web application archive BBYPServer.war
Dec 7, 2007 1:18:53 PM org.apache.catalina.core.ApplicationContext log
INFO: ContextListener: contextInitialized()
Dec 7, 2007 1:18:53 PM org.apache.catalina.core.ApplicationContext log
INFO: SessionListener: contextInitialized()
Dec 7, 2007 1:18:53 PM org.apache.coyote.http11.Http11Protocol start
INFO: Starting Coyote HTTP/1.1 on http-8888
Dec 7, 2007 1:18:53 PM org.apache.jk.common.ChannelSocket init
INFO: JK: ajp13 listening on /0.0.0.0:8009
Dec 7, 2007 1:18:54 PM org.apache.jk.server.JkMain start
INFO: Jk running ID=0 time=0/43  config=null
Dec 7, 2007 1:18:54 PM org.apache.catalina.startup.Catalina start
INFO: Server startup in 3005 ms

There is a warning about the docBase attribute (strange; I copied that text verbatim from the Tomcat FAQ); if I remove that attribute, the warning goes away, but the DataSource remains uninitialized.

- Thomas

David Smith wrote:
Where did you place your mysql driver jar file? It has to be in tomcat's /lib directory to be visible to tomat's internal code for building the db pool and your webapp. Also did you happen to look at the logs around when your webapp started for any relevant messages?

--David

Thomas Okken wrote:

Hi all,

I'm trying to set up a DataSource to manage connections to a MySQL database, but whenever I call getConnection(), I get this error:

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:1150) at org.apache.tomcat.dbcp.dbcp.BasicDataSource.getConnection(BasicDataSource.java:880)
    ...
Caused by: java.sql.SQLException: No suitable driver
    at java.sql.DriverManager.getDriver(DriverManager.java:243)
at org.apache.tomcat.dbcp.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:1143)
    ...


The datasource is defined in a file called $TOMCAT_HOME/conf/Catalina/localhost/smm.xml (the web app's context path is /smm); it looks like this:

<Context path="/smm" docBase="smm" debug="5" reloadable="true" crossContext="true"> <Resource name="jdbc/SmmDB" auth="Container" type="javax.sql.DataSource"
               maxActive="100" maxIdle="30" maxWait="10000"
username="wmmdev" password="wmmdev" driverClassName="com.mysql.jdbc.Driver" url="jdbc:mysql://ss-1.research.att.com:3306/wmmdev?autoReconnect=true"/>
</Context>

The fact that the datasource gets created and bound in JNDI tells me that smm.xml is getting read, but apparently it is not getting initialized properly; getDriverClassName(), getUrl(), getUsername(), and getPassword() all return null, and it looks like that's what causes the exception in getConnection(). I've seen quite a few questions about this error, but in the archived threads on this mailing list, I haven't found any solution to this particular problem... One poster who had the same diagnosis mentioned that the problem went away when he got rid of the Context element in META-INF/context.xml, but in my case, that file does not exist; in fact, the only Context elements I have are the one shown above, and the standard one in $TOMCAT_HOME/conf/context.xml. The MySQL JDBC driver is in $TOMCAT_HOME/lib, and when I do Class.forName("com.mysql.jdbc.Driver") in a JSP, it succeeds, but I'm not sure that's relevant because, first of all, DriverManager will only use drivers that were loaded by the same class loader as itself, and second, the DataSource can't use the driver anyway as long as its driverClassName and url properties remain unset.

I'm using Tomcat 6.0.14, JDK 1.5.0_11, MySQL 5.0.45, and mysql-connector-java-5.1.5-bin.jar.

I'm stumped... Any thoughts would be much appreciated!

- Thomas

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



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


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

Reply via email to