5

嗨,当我尝试使用 JNDI 连接到数据源时,出现此错误:

    [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 org.apache.roller.weblogger.business.DatabaseProvider.getConnection(DatabaseProvider.java:179)
    at org.apache.roller.weblogger.business.DatabaseProvider.<init>(DatabaseProvider.java:141)
    at org.apache.roller.weblogger.business.startup.WebloggerStartup.prepare(WebloggerStartup.java:171)
    at org.apache.roller.weblogger.ui.core.RollerContext.contextInitialized(RollerContext.java:138)
    at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4205)
    at org.apache.catalina.core.StandardContext.start(StandardContext.java:4704)
    at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:799)
    at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:779)
    at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:601)
    at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:1079)
    at org.apache.catalina.startup.HostConfig.deployDirectories(HostConfig.java:1002)
    at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:506)
    at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1315)
    at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:324)
    at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:142)
    at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1061)
    at org.apache.catalina.core.StandardHost.start(StandardHost.java:840)
    at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1053)
    at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:463)
    at org.apache.catalina.core.StandardService.start(StandardService.java:525)
    at org.apache.catalina.core.StandardServer.start(StandardServer.java:754)
    at org.apache.catalina.startup.Catalina.start(Catalina.java:595)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:289)
    at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:414)
Caused by: java.lang.NullPointerException
    at sun.jdbc.odbc.JdbcOdbcDriver.getProtocol(JdbcOdbcDriver.java:507)
    at sun.jdbc.odbc.JdbcOdbcDriver.knownURL(JdbcOdbcDriver.java:476)
    at sun.jdbc.odbc.JdbcOdbcDriver.acceptsURL(JdbcOdbcDriver.java:307)
    at java.sql.DriverManager.getDriver(DriverManager.java:253)
    at org.apache.tomcat.dbcp.dbcp.BasicDataSource.createConnectionFactory(BasicDataSource.java:1437)
    ... 30 more]

上下文.xml

<Context path="/roller" docBase="c:\Program Files\Apache Software Foundation\Tomcat 6.0\webapps\roller" debug="0">
    <Resource name="jdbc/rollerdb" auth="Container"
        type="javax.sql.DataSource"
        driverClassName="com.mysql.jdbc.Driver"
        url="jdbc:mysql://localhost:3306/rollerdb?autoReconnect=true&amp;useUnicode=true&amp;characterEncoding=utf8-&amp;mysqlEncoding=utf8"
        username="roller_user"
        password="password"
        maxActive="20" maxIdle="3" removeAbandoned="true"
        maxWait="3000" 
    />
    <Resource name="mail/Session"
        auth="Container"
        type="javax.mail.Session"
        username="username@gmail.com"
        password="password"
        mail.debug="false"
        mail.user="username@gmail.com"
        mail.password="password"
        mail.smtp.from="username@gmail.com"
        mail.transport.protocol="smtp"
        mail.smtp.port="465"
        mail.smtp.host="smtp.gmail.com"
        mail.smtp.auth="true"
        mail.smtp.starttls.enable="true"
        mail.smtp.socketFactory.port="465"
        mail.smtp.socketFactory.class="javax.net.ssl.SSLSocketFactory"
        mail.smtp.socketFactory.fallback="false" 
    />
</Context>

web.xml

<web-app .. >
...
    <!-- jndi resources -->
    <resource-ref>
        <res-ref-name>jdbc/rollerdb</res-ref-name>
        <res-type>javax.sql.DataSource</res-type>
        <res-auth>Container</res-auth>
    </resource-ref>

    <resource-ref>
        <res-ref-name>mail/Session</res-ref-name>
        <res-type>javax.mail.Session</res-type>
        <res-auth>Container</res-auth>
    </resource-ref>

</web-app>

滚筒-custom.properties

installation.type=auto
database.configurationType=jndi
database.jndi.name=jdbc/rollerdb
mail.configurationType=jndi
mail.jndi.name=mail/Session

我在 tomcat 的 lib 目录中有 mysql-connector-java-5.1.15-bin.jar、activation.jar 和 mail.jar,在 tomcat 的 webapps 文件夹中有 web 应用程序滚轮。

我无法理解我在这里做错了什么。有人可以帮助我了解我在这里缺少什么吗?

谢谢。

谢谢。

4

4 回答 4

1

我刚刚遇到了一个类似的错误,结果发现我的 context.xml 文件略有损坏。我认为这很可能是问题所在。

我的建议是在我和你之间比较 context.xml 文件,我说试试这个

driverClass

代替

driverClassName
于 2011-07-01T17:19:15.820 回答
0

在我的情况下,帮助进行了以下更改:在 APPLICATION_PATH/WebContent/META_INF/context.xml

旧代码:

<resource name="jdbc/internships_db" auth="Container" type="javax.sql.DataSource">
    <param name="username" value="my_user" />
    <param name="password" value="my_password" />
    <param name="url" value="jdbc:mysql://localhost:3306/internships_db" />
</resource>

新代码:

<Resource name="jdbc/internships_db"
    auth="Container"
    type="javax.sql.DataSource"
    maxActive="100"
    maxIdle="30"
    username="my_user"
    maxWait="10000"
    driverClassName="com.mysql.jdbc.Driver"
    password="my_password"  
    url="jdbc:mysql://localhost:3306/internships_db"/>

jdbc-Driver类放在路径/user_path/tomcat-instance_path/webapps/app_name/WEB-INF/lib/com.mysql.jdbc_5.1.5.jar下

于 2013-10-22T09:15:28.133 回答
0

如果您的 Tomcat 版本不同,您也可能会遇到此错误..那么您的 context.xml 必须看起来不同...有关详细信息,请访问此页面 ..必须阅读此问题:

http://www.crazysquirrel.com/computing/java/connection-pooling.jspx

regs Karthic

于 2013-10-09T05:31:36.020 回答
0

我已经解决了这个问题,将导入参考(在我的情况下)从以下位置更改:

import org.apache.tomcat.dbcp.dbcp.BasicDataSource;

import org.apache.commons.dbcp.BasicDataSource;

产生我的错误是因为我总是使用 CRTL+o 来导入引用,而当我进行导入时,我的引用中没有 .jar。我希望这对其他人有用。

于 2013-05-27T18:45:51.350 回答