首先我们需要创建一个连接池对象
ComboPooledDataSource pool = new ComboPooledDataSource();
第一种:直接调用:
pool.setDriverClass(com.mysql.jdbc.Driver);
pool.setJdbcUrl(jbdc:mysql:///jt_db?characterEncoding=utf-8);
pool.setUser(“root”);
pool.setPassword(“root”);
第二种,根据配置文件实现:
创建c3p0.propertise配置文件
输入:
c3p0.driverClasee=com.mysql.jdbc.Driver
c3p0.jdbcUrl=jdbc:mysql:///jt_db?characterEncoding=utf-8
c3p0.user=root
c3p0.password=root
第三种,根据xml配置文件实现:
创建c3p0-config.xml配置文件
输入:
<?xml version="1.0" encoding="UTF-8"?>
<c3p0-config>
<default-config>
<property name="driverClass">
com.mysql.jdbc.Driver
</property>
<property name="jdbcUrl">
jdbc:mysql:///jt_db?characterEncoding=utf-8
</property>
<property name="user">
root
</property>
<property name="password">
root
</property>
</default-config>
</c3p0-config>