这个问题已经有很多答案了,但没有一个对我有用。我觉得我什么都试过了。其他人有什么想法吗?
代码:
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)