Tomcat 6.0+mysql+C3P0 配置连接池方法
其实很简单,不知道,网上说的怎么那么罗嗦...
只需要修改三个文件^_^
前提条件:
拷贝Mysql 和 C3P0 jar包到 {TOMCATHOME}/lib下面
1. 修改{TOMCATHOME}/conf/server.xml文件
在
<GlobalNamingResources> …… </ GlobalNamingResources >
1
<GlobalNamingResources>……</GlobalNamingResources>
欢迎大家阅读《Tomcat 6.0+Mysql+C3P0 配备连接池方法》,跪求各位点评,by 搞代码
之间添加自己的jndi资源,如下
<Resource name="jdbc/mysql" auth="Container" description="DB Connection" factory="org.apache.naming.factory.BeanFactory" type="com.mchange.v2.c3p0.ComboPooledDataSource" driverClass="com.mysql.jdbc.Driver" jdbcUrl="jdbc:mysql://localhost:3306/pubdemo?autoReconnect=true" user="root" password="123" maxPoolSize="15" minPoolSize="2" acquireIncrement="1" />
1
<Resourcename="jdbc/mysql"auth="Container"description="DB Connection"factory="org.apache.naming.factory.BeanFactory"type="com.mchange.v2.c3p0.ComboPooledDataSource"driverClass="com.mysql.jdbc.Driver"jdbcUrl="jdbc:mysql://localhost:3306/pubdemo?autoReconnect=true"user="root"password="123"maxPoolSize="15"minPoolSize="2"acquireIncrement="1"/>
2. 修改{TOMCATHOME}/conf/context.xml
添加如下片段
global="jdbc/mysql"
type="java.lang.Integer"/>
<ResourceLink name="pubdemoJNDI" global="jdbc/mysql" type="java.lang.Integer"/>
1
<ResourceLinkname="pubdemoJNDI"global="jdbc/mysql"type="java.lang.Integer"/>
3. 修改WEB-INF/web.xml文件
其中添加JNDI引用
<resource-ref> <description>DB Connection</description> <res-ref-name>zhang</res-ref-name> <res-type>javax.sql.DataSource</res-type> <res-auth>Container</res-auth> </resource-ref>
1
<resource-ref><description>DBConnection</description><res-ref-name>zhang</res-ref-name><res-type>javax.sql.DataSource</res-type><res-auth>Container</res-auth></resource-ref>
4. 在你自己的程序中调用,如:
ds=(DataSource)ctx.lookup("java:comp/env/pubdemoJNDI");
CSDN本人原创:准备搬家至ITEYE.版权所有@Robot_G
1 楼 Technoboy 2011-06-24
jdbcUrl="jdbc:mysql://localhost:3306/pubdemo?autoReconnect=true"
这里的autoReconnect= true 一项非常危险的配置项
微信 赏一包辣条吧~
支付宝 赏一听可乐吧~