日期:2014-05-18  浏览次数:20755 次

mysql 连接池
我按照如下方法配制连接池,但运行时总是提示此错误Cannot   load   JDBC   driver   class   'com.mysql.jdbc.Driver ',谢谢哪位高手帮帮忙,急
配制方法:
1.在conf/context.xml   里添加
      <Resource   name= "jdbc/MysqlDB "   auth= "Container "   type= "javax.sql.DataSource "   maxActive= "100 "   maxIdle= "30 "   maxWait= "10000 "   username= "root "   password= "root "     driverClassName= "com.mysql.jdbc.Driver "     url= "jdbc:mysql://localhost:3306/mysql?autoReconnect=true "/>

其中不用字段分别代表不用意思.数据库名,用户名,密码等,其中mysql为数据库的名称
2.在工程目录里的web.xml添加
<resource-ref>
            <description> DB   Connection </description>
            <res-ref-name> jdbc/MysqlDB </res-ref-name>
            <res-type> javax.sql.DataSource </res-type>
            <res-auth> Container </res-auth>
</resource-ref>


3.添加数据库的驱动,放在tomcat里的comm/lib里.文件mysql-connector-java-3.1.18-bin-g.jar

------解决方案--------------------
不知道你是在那学的配置POOL
1、把数据库JDBC驱动拷贝到%TOMCAT_HOME%/common/lib(必须)和%TOMCAT_HOME%/webapps/yourweb/WEB-INF/lib下这一步大家都知道,不然tomcat无法与数据库连接。
2、修改%TOMCAT_HOME%/conf/server.xml文件,在 <GlobalNamingResources> </GlobalNamingResources> 之间
添加以下内容:
<Resource
name= "jdbc/quickstart "
type= "javax.sql.DataSource "
password= "123456 "
driverClassName= "com.microsoft.jdbc.sqlserver.SQLServerDriver "
maxIdle= "2 "
maxWait= "5000 "
username= "sa "
url= "jdbc:microsoft:sqlserver://localhost;DatabaseName=quickstart "
maxActive= "4 "/>
要是使用ADMIN模块的话直接在里面datasouce
3在%TOMCAT_HOME%/conf/Catalina/localhost下新建一个与你web文件夹同名的xml文件这一步非常重要,如果没有这步就会出错,会出现
org.apache.tomcat.dbcp.dbcp.SQLNestedException: Cannot create JDBC driver of class ' ' for connect URL 'null '

<?xml version= "1.0 " encoding= "UTF-8 "?>
<Context>
<Resource
name= "jdbc/quickstart "
type= "javax.sql.DataSource "
password= "123456 "
driverClassName= "com.microsoft.jdbc.sqlserver.SQLServerDriver "
maxIdle= "2 "
maxWait= "5000 "
username= "sa "
url= "jdbc:microsoft:sqlserver://localhost;DatabaseName=quickstart "
maxActive= "4 "/>
对于TOMCAT5.5使用这个方法
5.0的conf/Catalina/localhost已经存在同名的XML了只需要加入
<ResourceLink global= "jdbc/**** " name= "jdbc/**** " type= "javax.sql.DataSourcer "/>
6.0的conf不存在Catalina/localhost 我是自己建立的这两个文件夹加入的同名XML内容和5.5的一样

<resource-ref>
<description> sqlserverDB Connection </description>
<res-ref-name> jdbc/quickstart </res-ref-name>
<res-type> javax.sql.DataSource </res-type>
<res-auth> Container </res-auth>
</resource-ref>
我没加过但是POOL都是好用的