Tomcat6 mysql 连接池配置

来源:互联网 发布:it 全称 编辑:程序博客网 时间:2024/05/22 15:05

最近在网上看到的java+jsp+ tomcat6+ mysql 连接池大多数是tomcat5 的,很多都说得不详细,并且配置不起,让我们很费时间,也很脑火,今天我终于把最新的tomcat6+mysql的连接池配置成功了,现在分享如下:

 

1.需要的文件:

mysql-5.0.27-win32.zip(安装文件),mysql-connector-java-5.0.4-bin.jar(连接驱动程序),apache-tomcat-6.0.10.exe(安装文件)

 

2.配置tomcat下的conf下的context.xml文件

 

在<context></context>之间添加连接池如下:

  1. <Resource name="jdbc/mysql"  
  2.        auth="Container"  
  3.           
  4.        type="javax.sql.DataSource"  
  5.        driverClassName="com.mysql.jdbc.Driver"  
  6.        url="jdbc:mysql://localhost/test"  
  7.        username="root"  
  8.        password="root"  
  9.        maxActive="100"  
  10.        maxIdle="30"  
  11.        maxWait="10000" />  

                   上面的参数不用我说了吧,这些都知道是什么意思吧.

 

3.配置你的应用下的web.xml

 

<web-app></web-app>之间加入:

xml 代码
  1. <resource-ref>  
  2.     <description>DB Connection</description>  
  3.     <res-ref-name>jdbc/mysqlx</res-ref-name>  
  4.     <res-type>javax.sql.DataSource</res-type>  
  5.     <res-auth>Container</res-auth>  
  6.   </resource-ref>  

4.大功告成

 

不用在原来的server.xml里面配置了,下面就可以编写测试程序了,这个网上就很多了,主要的就上面,当然要把连接驱动程序都放到tomcat6下的lib下面.

 

gengv: 经过验证,成功。