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]