无法为连接url'null'postgresql创建类''的jdbc驱动程序

时间:2013-04-25 10:07:24

标签: xml java-ee jdbc tomcat6 postgresql-8.4

当我尝试部署WAR应用程序时,我收到此错误。

org.apache.tomcat.dbcp.dbcp.SQLNestedException: Cannot create JDBC driver of cla
ss '' for connect URL 'null'
        at org.apache.tomcat.dbcp.dbcp.BasicDataSource.createConnectionFactory(B
asicDataSource.java:1452)
        at org.apache.tomcat.dbcp.dbcp.BasicDataSource.createDataSource(BasicDat
aSource.java:1371)
        at org.apache.tomcat.dbcp.dbcp.BasicDataSource.getConnection(BasicDataSo
urce.java:1044)
        at kimet.ConexionSQL.getConexion(ConexionSQL.java:20)
        at kimet.Global.cargarHashtablesAux(Global.java:2360)
        at kimet.Inicio.init(Inicio.java:33)
        at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.
java:1206)
        at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:10
26)
        at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContex
t.java:4421)
        at org.apache.catalina.core.StandardContext.start(StandardContext.java:4
734)
        at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase
.java:799)
        at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:77
9)
        at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:601)

        at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:943)

        at org.apache.catalina.startup.HostConfig.deployWARs(HostConfig.java:778
)
        at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:504
)
        at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1317)
        at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java
:324)
        at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(Lifecycl
eSupport.java:142)
        at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1065)

        at org.apache.catalina.core.StandardHost.start(StandardHost.java:840)
        at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1057)

        at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:463
)
        at org.apache.catalina.core.StandardService.start(StandardService.java:5
25)
        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(DelegatingMethodAcces
sorImpl.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(B
asicDataSource.java:1437)
        ... 31 more
org.apache.tomcat.dbcp.dbcp.SQLNestedException: Cannot create JDBC driver of cla
ss '' for connect URL 'null'
        at org.apache.tomcat.dbcp.dbcp.BasicDataSource.createConnectionFactory(B
asicDataSource.java:1452)
        at org.apache.tomcat.dbcp.dbcp.BasicDataSource.createDataSource(BasicDat
aSource.java:1371)
        at org.apache.tomcat.dbcp.dbcp.BasicDataSource.getConnection(BasicDataSo
urce.java:1044)
        at kimet.ConexionSQL.getConexion(ConexionSQL.java:20)
        at kimet.Global.cargarHashtablesAux(Global.java:2360)
        at kimet.Inicio.init(Inicio.java:33)
        at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.
java:1206)
        at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:10
26)
        at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContex
t.java:4421)
        at org.apache.catalina.core.StandardContext.start(StandardContext.java:4
734)
        at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase
.java:799)
        at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:77
9)
        at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:601)

        at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:943)

        at org.apache.catalina.startup.HostConfig.deployWARs(HostConfig.java:778
)
        at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:504
)
        at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1317)
        at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java
:324)
        at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(Lifecycl
eSupport.java:142)
        at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1065)

        at org.apache.catalina.core.StandardHost.start(StandardHost.java:840)
        at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1057)

        at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:463
)
        at org.apache.catalina.core.StandardService.start(StandardService.java:5
25)
        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(DelegatingMethodAcces
sorImpl.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(B
asicDataSource.java:1437)
        ... 31 more
--- Inicializado KimetSport  --- Thu Apr 25 11:16:13 CEST 2013
25-abr-2013 11:16:13 org.apache.catalina.startup.HostConfig deployDirectory
INFO: Despliegue del directorio docs de la aplicaci¾n web
25-abr-2013 11:16:13 org.apache.catalina.startup.HostConfig deployDirectory
INFO: Despliegue del directorio examples de la aplicaci¾n web
25-abr-2013 11:16:14 org.apache.catalina.startup.HostConfig deployDirectory
INFO: Despliegue del directorio ROOT de la aplicaci¾n web
25-abr-2013 11:16:14 org.apache.coyote.http11.Http11AprProtocol start
INFO: Arrancando Coyote HTTP/1.1 en puerto http-8080
25-abr-2013 11:16:14 org.apache.coyote.ajp.AjpAprProtocol start
INFO: Arrancando Coyote AJP/1.3 en ajp-8009
25-abr-2013 11:16:14 org.apache.catalina.startup.Catalina start
INFO: Server startup in 4540 ms

我向您展示了我修改过的文件:

首先,在Tomcat的context.xml文件中:

<Context reloadable="true" privileged="true">
    <!-- Default set of monitored resources -->
    <WatchedResource>WEB-INF/web.xml</WatchedResource>
</Context>

在web.xml文件中:

<resource-ref>
    <!-- <description>DB Kimet</description> -->
    <res-ref-name>modulo/KIMET</res-ref-name>
    <res-type>javax.sql.DataSource</res-type>
    <res-auth>Container</res-auth>
    <!-- <res-sharing-scope>Shareable</res-sharing-scope> -->
</resource-ref>

最后,我创建了自己的xml文件&#34; aKS.xml&#34;在目录&#34; conf \ Catalina \ localhost&#34;

<?xml version='1.0' encoding='utf-8'?>
    <Context crossContext="true" displayName="Kimet Sport" docBase="C:/Workarea/kimetsportweb/WebContent" path="/aKS" reloadable="true">
    <Resource name="modulo/KIMET"
    auth="Container"
    type="javax.sql.DataSource"
    factory="org.apache.commons.dbcp.BasicDataSourceFactory"
    defaultAutoCommit="false"
    removeAbandoned="false"
    removeAbandonedTimeout="30"
    maxActive="50"
    maxIdle="20"
    maxWait="10000"
    username="usukimet"
    password="usukimet"
    driverClassName="org.postgresql.Driver"
    url="jdbc:postgresql://192.168.1.169:5432/kimet_desarrollo"/>       
</Context>

任何人都知道为什么不工作? 任何建议都会受到欢迎! 提前谢谢!

1 个答案:

答案 0 :(得分:0)

你的aKS.xml档案是什么?

如果要在应用程序之外的Tomcat中为WAR指定数据源,则必须在context.xml中对其进行配置,例如:

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

(取自Tomcat的JNDI Datasource HOW-TO。)