2

I am getting the above exception, and I don't know why. Here is some more information:

Cannot create JDBC driver of class 'com.mysql.jdbc.Driver' for connect URL 'jdbc:mysql://localhost:3306/staffing_2014'

I am using Spring. In the Spring application context, I have the following dataSource:

<jee:jndi-lookup id="dataSource"
    jndi-name="jdbc/StaffingDB"
    expected-type="javax.sql.DataSource" />

It seems to read the database URL and credentials OK from tomcat's context.xml:

<Resource name="jdbc/StaffingDB" auth="Container" type="javax.sql.DataSource"
           maxActive="100" maxIdle="30" maxWait="10000"
           username="xxx" password="yyy" driverClassName="com.mysql.jdbc.Driver"
           url="jdbc:mysql://localhost:3306/staffing_2014"/>

Before anyone suggests Googling it, I have. The obvious answers I've found have been:

  • Database URL malformed? - checked and OK.
  • MySQL driver in classpath? Yes- jar is in $TOMCAT_HOME/lib

Any other suggesions?

EDIT - way down the bottom:

java.sql.SQLException: No suitable driver
java.sql.DriverManager.getDriver(DriverManager.java:279)
org.apache.tomcat.dbcp.dbcp.BasicDataSource.createConnectionFactory(BasicDataSource.java:1437)
org.apache.tomcat.dbcp.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:1371)
org.apache.tomcat.dbcp.dbcp.BasicDataSource.getConnection(BasicDataSource.java:1044)
org.springframework.jdbc.datasource.DataSourceUtils.doGetConnection(DataSourceUtils.java:111)
org.springframework.jdbc.datasource.DataSourceUtils.getConnection(DataSourceUtils.java:77)
9
  • You did create the database "staffing_2014"? Commented Nov 5, 2013 at 16:23
  • Is there a specific Exception being thrown (e.g. NoClassDefFoundException or ClassNotFoundException)? Commented Nov 5, 2013 at 16:24
  • @RaunakAgarwal yes the database certainly exists Commented Nov 5, 2013 at 16:26
  • 1
    @NickJ can you write a simple JSP inside a separate clean web app that uses the JNDI resource jdbc/StaffingDB and tries to connect to the db as a test? If it works then the issue is with the Spring layer Commented Nov 5, 2013 at 16:35
  • 1
    @NickJ check this post out: stackoverflow.com/questions/10354997/… - are you hitting the same issue? Commented Nov 5, 2013 at 16:55

1 Answer 1

1

What version of Tomcat are you using? In some Tomcats (T5), TOMCAT_HOME/lib may not be the right location. You have to put the driver in Tomcat's endorsed folder which could be

  • TOMCAT_HOME/endorsed or
  • TOMCAT_HOME/shared/lib

Check your Tomcat setup.

Sign up to request clarification or add additional context in comments.

4 Comments

The version is 6.0.35. The endorsed and shared directories do not exist. The lib directory is correct according to the Tomcat JNDI HowTo at tomcat.apache.org/tomcat-6.0-doc/…
I think it's better to put the .jar file in webapps/$yourAppName/WEB-INF/lib
I had it there originally. I wanted to move it out to try and avoid a memory leak when redeploying.
You can only put the jdbc driver in webapp/WEB-INF/lib if you define the jndi resource within the web app. So if your context.xml is in Tomcat's conf/ folder then you need to add the library to Tomcat's lib folder.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.