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

TOMCAT数据库连接池的配置方法总结

?

?

MySQL+TOMCAT 为例
1.
DataSource 设置到我们的WEB 项目中,下面详细的介绍下:
第一步:在我们的WEB 项目中的META-INF 文件夹下建立一个context.xml

Xml 代码 复制代码

?

<?xml version='1.0' encoding='utf-8'?>

?

<Context>

?

??? <Resource name="jdbc/mysql"??

?????? auth="Container"??

?????? type="javax.sql.DataSource"??

?????? driverClassName="com.mysql.jdbc.Driver"??

?????? url="jdbc:mysql://localhost/bbs"??

?????? username="root"??

?????? password="root"??

?????? maxActive="50"??

?????? maxIdle="20"??

?????? maxWait="10000" />??

?

</Context>


第二步:在我们的WEB 项目下的WEB-INF 文件夹下建立一个web.xml ( 如果存在了就不用了,直接修改就行了)
(
这几天测试了一下,不做这步也可以,O(∩_∩)O 哈哈~ 省事了)

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>  
?

? <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>

? &l