简体   繁体   English

无法为连接URL''创建类''的JDBC驱动程序

[英]Cannot create JDBC driver of class '' for connect URL 'null'

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

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)

The postgresql JDBC driver is in my CATALINA/lib folder. postgresql JDBC驱动程序位于我的CATALINA / lib文件夹中。

Here is my META-INF/context.xml: 这是我的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>

Here is my WEB-INF/web.xml: 这是我的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>

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

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. 为了让所有3个webapps正确使用相同的数据源,我必须将所有<Resource>条目从META-INF / context.xml文件夹移动到服务器的$ CATALINA_BASE / conf / context.xml文件夹中。 Not a great solution, but it works. 不是一个很好的解决方案,但它确实有效

我遇到了同样的问题,结果是我在context.xml上的<Resource>名称声明与web.xml上<resource-ref> name上定义的名称声明不匹配。

As answered above, one solution is to move the entries to $CATALINA_BASE/conf/context.xml 如上所述,一种解决方案是将条目移动到$ CATALINA_BASE / conf / context.xml

Another approach is described here: http://blogs.agilefaqs.com/2009/11/23/cannot-create-jdbc-driver-of-class-for-connect-url-null/ 这里描述了另一种方法: http//blogs.agilefaqs.com/2009/11/23/cannot-create-jdbc-driver-of-class-for-connect-url-null/

In particular, "Copy the Context.xml file to tomcat/conf/Catalina/localhost folder and renaming it to <web_app_name>.xml " 特别是,“将Context.xml文件复制到tomcat / conf / Catalina / localhost文件夹并将其重命名为<web_app_name>.xml

The underlying cause could be due to a problem with file permissions: "The user under which tomcat was running did not have permission to write to these folders. So we changed the group ownership of tomcat and /etc/tomcat folder to the same group to which the tomcat user belonged and magically everything started working as before." 根本原因可能是由于文件权限问题:“运行tomcat的用户没有写入这些文件夹的权限。所以我们将tomcat和/ etc / tomcat文件夹的组所有权更改为同一组这是tomcat用户所属的,而且神奇的一切都像以前一样开始运作。“

This solution seems 'cleaner' to me because you can then have your entire web app including database connection properties wrapped up in a .war file. 这个解决方案对我来说似乎“更清洁”,因为您可以将整个Web应用程序(包括数据库连接属性)包含在.war文件中。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 无法一直为连接URL&#39;null创建类&#39;&#39;的JDBC驱动程序 - Cannot create JDBC driver of class '' for connect URL 'null all the time 带有mysql的Tomcat:“无法为连接URL&#39;null&#39;创建类”的JDBC驱动程序” - Tomcat with mysql : “ Cannot create JDBC driver of class '' for connect URL 'null' ” 无法为连接URL null创建类的JDBC驱动程序 - Cannot create JDBC driver of class for connect URL null 无法为连接URL&#39;null&#39;Oracle创建类&#39;&#39;的JDBC驱动程序 - Cannot create JDBC driver of class '' for connect URL 'null' Oracle 无法为连接URL&#39;null&#39;和NullPointerException创建类&#39;&#39;的JDBC驱动程序 - Cannot create JDBC driver of class '' for connect URL 'null' and NullPointerException 无法创建 class“”的 JDBC 驱动程序用于连接 URL 'null' - Cannot create JDBC driver of class “” for connect URL 'null' 无法为连接URL&#39;null&#39;创建类&#39;&#39;的JDBC驱动程序:Tomcat和SQL Server JDBC驱动程序 - Cannot create JDBC driver of class '' for connect URL 'null' : Tomcat & SQL Server JDBC driver 无法为连接 URL 的 class '' 创建 JDBC 驱动程序 - Cannot create JDBC driver of class '' for connect URL 在tomcat 6中创建和使用数据源时,无法为连接URL&#39;null&#39;-:ERROR创建类&#39;&#39;的JDBC驱动程序 - Cannot create JDBC driver of class '' for connect URL 'null' -:ERROR while creating and using a Datasource in tomcat 6 无法为连接URL&#39;null&#39;创建类&#39;&#39;的JDBC驱动程序:Tomcat + MySQL + Spring MVC - Cannot create JDBC driver of class '' for connect URL 'null' : Tomcat + MySQL + Spring MVC
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM