日期:2014-05-16  浏览次数:20429 次

连接数据库错误Cannot create JDBC driver of class '' for connect URL 'null'
  • mysql:
  1. 修改\conf\Catalina\localhost目录下建立一个xml文件,名称为你所发布的web应用的名称.xml,(如test.xml)打开添加内容如下:

?

<?xml version="1.0" encoding="UTF-8"?>
<Context>
 <Resource
      name="jdbc/mysql"
      type="javax.sql.DataSource"      
      driverClassName="com.mysql.jdbc.Driver"
      url="jdbc:mysql://localhost:3306/test"
      username="root"
      password="root"
      maxActive="4"/>
      maxWait="50"
      maxIdle="2"
</Context>
?

?


???? 2.?? 修改web.xml


?????? 打开%TOMCAT_HOME%\conf\web.xml或mywebapp/web-inf/web.xml,添加以下内容:

?

<resource-ref>
        <description>DB Connection</description>
        <res-ref-name>jdbc/mysql</res-ref-name>
        <res-type>javax.sql.DataSource</res-type>
        <res-auth>Container</res-auth>
</resource-ref>
?

?

?????? 注意res-ref-name填写的内容要与配置的JNDI Name名称一致。

?

?

  • oracle

??????? 格式同上:

?

<?xml version="1.0" encoding="UTF-8"?>  
<Context reloadable="true" crossContext="true">  
 <Resource   
     name="jdbc/report"   
     auth="Container"  
     type="javax.sql.DataSource"  
     driverClassName="oracle.jdbc.driver.OracleDriver"  
     url="jdbc:oracle:thin:@192.168.200.115:1521:orcl"  
     username="report"  
     password="report"  
     maxActive="150"  
     maxIdle="500"  
     maxWait="2000"/>  
</Context>?

??????

??????? 注意name和url的配置。