无法为连接URL''创建类''的JDBC驱动程序 [英] Cannot create JDBC driver of class '' for connect URL 'null'

查看:128
本文介绍了无法为连接URL''创建类''的JDBC驱动程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Tomcat 7.0.12并且每当我通过名为ROOT的webapp中的.jsp页面访问连接到postgresql数据库的JNDI数据源时都会收到此错误:

I'm using Tomcat 7.0.12 and receiving this error whenever I attmept to access a JNDI datasource connecting to a postgresql db via a .jsp page in a webapp called 'ROOT':

SEVERE: Servlet.service() for servlet [jsp] in context with path [] threw exception
[java.lang.RuntimeException: Cannot create JDBC driver of class '' for connect URL 'null'] with root cause
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)
at org.apache.tomcat.dbcp.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:1371)
at org.apache.tomcat.dbcp.dbcp.BasicDataSource.getConnection(BasicDataSource.java:1044)

postgresql JDBC驱动程序位于我的CATALINA / lib文件夹中。

The postgresql JDBC driver is in my CATALINA/lib folder.

这是我的META-INF / context.xml:

Here is my META-INF/context.xml:

<?xml version="1.0" encoding="UTF-8"?>

<Context>

<Resource name="jdbc/webdbro" auth="Container" type="javax.sql.DataSource"
    driverClassName="org.postgresql.Driver" url="jdbc:postgresql://127.0.0.1:5432/webdb"
    username="webdbro" password="pass" maxWait="-1" removeAbandoned="true" removeAbandonedTimeout="30"/>

<Resource name="jdbc/webdbrw" auth="Container" type="javax.sql.DataSource"
    driverClassName="org.postgresql.Driver" url="jdbc:postgresql://127.0.0.1:5432/webdb"
    username="webdbrw" password="pass" maxWait="-1" removeAbandoned="true" removeAbandonedTimeout="30"/>

<Resource name="jdbc/shadowdbro" auth="Container" type="javax.sql.DataSource"
    driverClassName="org.postgresql.Driver" url="jdbc:postgresql://127.0.0.1:5432/shadowdb"
    username="shadowdbro" password="pass" maxWait="-1" removeAbandoned="true" removeAbandonedTimeout="30"/>

</Context>

这是我的WEB-INF / web.xml:

Here is my WEB-INF/web.xml:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
id="WebApp_ID" version="3.0">
<display-name>ROOT</display-name>

<resource-ref>
    <description>Read only webdb connector.</description>
    <res-ref-name>jdbc/webdbro</res-ref-name>
    <res-type>javax.sql.DataSource</res-type>
    <res-auth>Container</res-auth>
</resource-ref>
<resource-ref>
    <description>Read write webdb connector.</description>
    <res-ref-name>jdbc/webdbrw</res-ref-name>
    <res-type>javax.sql.DataSource</res-type>
    <res-auth>Container</res-auth>
</resource-ref>
<resource-ref>
    <description>Read only shadow db connector.</description>
    <res-ref-name>jdbc/shadowdbro</res-ref-name>
    <res-type>javax.sql.DataSource</res-type>
    <res-auth>Container</res-auth>
</resource-ref>

<welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
</welcome-file-list>

</web-app>

奇怪的是我使用完全相同的配置在同一个Tomcat服务器上运行了2个其他webapps (web.xml和context.xml)所以他们可以使用JNDI方法连接到数据库,这些webapps的两个工作完全正常 - 我可以查询和更新数据库,在这些应用程序中没有任何问题或例外。 TIA ...

The weird thing is that I have 2 other webapps running on the same Tomcat server using the exact same configuration (web.xml and context.xml) so they can use the JNDI method to connect to the database and BOTH of those webapps work perfectly fine - I can query and update the database with no problems or exceptions in those apps. TIA...

推荐答案

为了让所有3个webapps正确使用相同的数据源,我不得不移动所有的< Resource> 从META-INF / context.xml文件夹到服务器的$ CATALINA_BASE / conf / context.xml文件夹中的条目。不是一个很好的解决方案,但它确实有效。

In order to get all 3 webapps to use the same datasource properly, I had to move all my <Resource> entries from the META-INF/context.xml folder into the server's $CATALINA_BASE/conf/context.xml folder. Not a great solution, but it works.

这篇关于无法为连接URL''创建类''的JDBC驱动程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆