Java 使用mysql的Tomcat:“;无法创建类';的JDBC驱动程序';用于连接URL';空'&引用;
这个问题已经被问了很多次了,但是它仍然不能解决我的问题 主机操作系统是Fedora17 Tomcat包Tomcat-7.0.27-2.fc17.noarch 这是我的$CATALINA_主页/logs/CATALINA.outJava 使用mysql的Tomcat:“;无法创建类';的JDBC驱动程序';用于连接URL';空'&引用;,java,mysql,tomcat,database-connection,jndi,Java,Mysql,Tomcat,Database Connection,Jndi,这个问题已经被问了很多次了,但是它仍然不能解决我的问题 主机操作系统是Fedora17 Tomcat包Tomcat-7.0.27-2.fc17.noarch 这是我的$CATALINA_主页/logs/CATALINA.out [DEBUG]: Failed to establish connection with datastore org.apache.tomcat.dbcp.dbcp.SQLNestedException: Cannot create JDBC driver of clas
[DEBUG]: Failed to establish connection with datastore
org.apache.tomcat.dbcp.dbcp.SQLNestedException: Cannot create JDBC driver of class '' for connect URL 'null'
at org.apache.tomcat.dbcp.dbcp.BasicDataSource.createConnectionFactory(BasicDataSource.java:1452)
at org.apache.tomcat.dbcp.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:1371)
at org.apache.tomcat.dbcp.dbcp.BasicDataSource.getConnection(BasicDataSource.java:1044)
...
...
Caused by: java.sql.SQLException: No suitable driver
at java.sql.DriverManager.getDriver(DriverManager.java:289)
at org.apache.tomcat.dbcp.dbcp.BasicDataSource.createConnectionFactory(BasicDataSource.java:1437)
...
这是我的$CATALINA_HOME/conf/CATALINA/localhost/ABC/ABC.xml
<Context path="/ABC">
<!-- maxActive: Maximum number of dB connections in pool. Make sure you
configure your mysqld max_connections large enough to handle
all of your db connections. Set to -1 for no limit.
-->
<!-- maxIdle: Maximum number of idle dB connections to retain in pool.
Set to -1 for no limit. See also the DBCP documentation on this
and the minEvictableIdleTimeMillis configuration parameter.
-->
<!-- maxWait: Maximum time to wait for a dB connection to become available
in ms, in this example 10 seconds. An Exception is thrown if
this timeout is exceeded. Set to -1 to wait indefinitely.
-->
<!-- username and password: DB username and KeyDB password key (not the password itself) -->
<!-- driverClassName: Class name for the JDBC KeyDB wrappers. These wrappers
replace the 'mysql_keydb_key' with its corresponding value from KeyDB
-->
<!-- url: The JDBC connection url for connecting to your MySQL dB.
The autoReconnect=true argument to the url makes sure that the
mm.mysql JDBC Driver will automatically reconnect if mysqld closed the
connection. mysqld by default closes idle connections after 8 hours.
-->
<Resource name="jdbc/last_db" auth="Container" type="javax.sql.DataSource" maxActive="100" maxIdle="30" maxWait="10000" username="****" password="****" driverClassName="com.mysql.jdbc.Driver" url="jdbc:mysql://localhost:3306/last_db"/>
</Context>
这是我的WEB-INF/WEB.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
version="2.5">
<servlet>
<servlet-name>jersey</servlet-name>
<servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>jersey</servlet-name>
<url-pattern>/v1/*</url-pattern>
</servlet-mapping>
<resource-ref>
<description>DB Connection</description>
<res-ref-name>jdbc/last_db</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
</web-app>
mysql连接器jar似乎在WEB-INF/lib中可用
$ jar tf ABC.war | grep mysql-connector
WEB-INF/lib/mysql-connector-java-5.1.0.jar
我不知道这是否有用,但这是端口3306的侦听端口信息
$ netstat -tln
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN
我想把头撞在桌子上 问题是没有保留ABC.xml $CATALINA_HOME/conf/CATALINA/localhost/ABC/ABC.xml 它应该保存在这里: $CATALINA_HOME/conf/CATALINA/localhost/ABC.xml
StackTrace对于连接器驱动程序的错误有很大的误导性。在部署的war中检查连接器jar是否在那里是的,它在那里。$jar tf ABC.war | grep mysql connector WEB-INF/lib/mysql-connector-java-5.1.0.jar再做一件事,把这个连接器jar放在tomcat lib文件夹中,然后再试一次请参考问题中指定的$CATALINA_HOME/lib文件夹的内容。连接器jar就在那里。你知道你只需要一次查找吗
initContext.lookup(“java:/comp/env/jdbc/”+dbName)
它告诉您Context.xml文件中的变量没有生效。。。
$ jar tf ABC.war | grep mysql-connector
WEB-INF/lib/mysql-connector-java-5.1.0.jar
$ netstat -tln
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN