第一种 全局配置
当你在Eclipse中添加完tomcat时,那么在Eclipse哪里就有一个servers项目,在servers项目下的context.xml文件中加入如下代码,就可以了
<Resource name = "jdbc/DataSource"
factory = "org.apache.naming.factory.BeanFactory"
type = "com.mchange.v2.c3p0.ComboPooledDataSource"
user="root"
password="123456"
driverClass="com.mysql.jdbc.Driver"
jdbcUrl="jdbc:mysql://127.0.0.1/mydb1"
maxPoolSize="20"
minPoolSize ="5"
initialPoolSize="10"
acquireIncrement="2"
/>
第二种 局部配置
在你web项目下的/WebContent/META-INF目录下新建content.xml,加入以下代码就可以了
<?xml version="1.0" encoding="UTF-8"?>
<Context>
<Resource name = "jdbc/DataSource"
factory = "org.apache.naming.factory.BeanFactory"
type = "com.mchange.v2.c3p0.ComboPooledDataSource"
user="root"
password="123456"
driverClass="com.mysql.jdbc.Driver"
jdbcUrl="jdbc:mysql://127.0.0.1/mydb1"
maxPoolSize="20"
minPoolSize ="5"
initialPoolSize="10"
acquireIncrement="2"
/>
</Context>