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)
4

1 回答 1

1

你用的是什么版本的Tomcat?在某些 Tomcats (T5) 中,TOMCAT_HOME/lib可能不是正确的位置。您必须将驱动程序放在 Tomcat 的认可文件夹中,该文件夹可能是

  • TOMCAT_HOME/认可或
  • TOMCAT_HOME/shared/lib

检查您的 Tomcat 设置。

于 2013-11-05T16:26:31.750 回答