这个问题已经有很多答案,但没有一个对我有用。我觉得我已经尝试了一切。其他人有什么想法吗?
代码:
private DataSource ds1;
private Connection dc1 = null;
Context initContext = new InitialContext();
Context envContext = (Context)initContext.lookup("java:comp/env");
ds1 = (DataSource)envContext.lookup("jdbc/CMS1-DEV");
dc1 = ds1.getConnection();
WEB-INF / web.xml中:
<resource-ref>
<description>CMS Data</description>
<res-ref-name>jdbc/CMS1-DEV</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
META-INF / context.xml中
<context>
<resource
name="jdbc/CMS1-DEV"
auth="Container"
type="jaxax.sql.DataSource"
username="******"
password="******"
driverClassName="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost:3306/bitnami_wordpress"
maxActive="10" maxIdle="4"/>
我在META-INF / lib目录中有mysql-connector-java-5.1.17.jar
堆栈跟踪:
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)
at us.deans.parrot.ParrotController.doPost(ParrotController.java:77)
答案 0 :(得分:1)
您的配置中存在拼写错误 - “jaxa”而不是“java”。
更改以下内容:
type="jaxax.sql.DataSource"
要
type="javax.sql.DataSource"