导三个包 c3p0 jar、mysql jar、commons-dbutils jar包
c3p0-config.xml配置文件
<?xml version="1.0" encoding="utf-8"?>
<c3p0-config>
<default-config>
<property name="jdbcUrl">jdbc:mysql://localhost:3306/das</property>
<property name="driverClass">com.mysql.jdbc.Driver</property>
<property name="user">root</property>
<property name="password">123456</property>
<property name="acquireIncrement">3</property>
<property name="initialPoolSize">10</property>
<property name="minPoolSize">2</property>
<property name="maxPoolSize">10</property>
</default-config>
</c3p0-config>
一个工具类
import com.mchange.v2.c3p0.ComboPooledDataSource;
public class C3p0Utils {
private static ComboPooledDataSource dataSource = new ComboPooledDataSource();
public static Connection getConnection() {
Connection conn = null;
try {
conn = dataSource.getConnection();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return conn;
}
public static DataSource getDataSource(){
return dataSource;
}
}