【问题标题】:tomcat.dbcp... Cannot create JDBC driver of class '' for connect URL 'null'tomcat.dbcp ... 无法为连接 URL 'null' 创建类 '' 的 JDBC 驱动程序
【发布时间】:2015-04-15 14:24:05
【问题描述】:

这个问题已经有很多答案了,但没有一个对我有用。我觉得我什么都试过了。其他人有什么想法吗?

代码:

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)

【问题讨论】:

  • 这里有错别字type="jaxax.sql.DataSource"应该是type="javax.sql.DataSource"
  • 大声笑 - 我花了一整天的时间在桌子上敲打我的头。什么都试过了。我想对于第二双眼睛有话要说。非常感谢你们,这确实是问题所在。
  • 你介意我在答案部分回答它以便帮助其他人吗?
  • 你可以试试:url="jdbc:mysql://127.0.0.1:3306/bitnami_wordpress"

标签: java mysql tomcat jdbc jdbc-pool


【解决方案1】:

您的配置中有一个错字 - “jaxa”而不是“java”。

更改以下内容:

type="jaxax.sql.DataSource" 

type="javax.sql.DataSource"

【讨论】:

    猜你喜欢
    • 2011-11-08
    • 2018-01-14
    • 2011-05-14
    • 2011-07-06
    • 2015-12-18
    • 2014-01-25
    • 2019-02-05
    • 1970-01-01
    相关资源
    最近更新 更多