使用C3P0和DBUtils
时间:2021-07-01 10:21:17
帮助过:15人阅读
xml version="1.0" encoding="UTF-8"?>
<c3p0-config>
<default-config>
<property name="driverClass">com.mysql.jdbc.Driver
</property>
<property name="jdbcUrl">jdbc:mysql:///表名?useSSL=true
</property>
<property name="user">用户名
</property>
<property name="password">密码
</property>
<property name="initialPoolSize">5
</property>
<property name="maxPoolSize">20
</property>
</default-config>
<named-config name="oracle">
<property name="driverClass">com.mysql.jdbc.Driver
</property>
<property name="jdbcUrl">jdbc:mysql:///表名?useSSL=true
</property>
<property name="user">用户名
</property>
<property name="password">密码
</property>
</named-config>
</c3p0-config>
3、创建C3P0Utils类
package C3P0Utils;
import java.sql.Connection;
import java.sql.SQLException;
import javax.sql.DataSource;
import com.mchange.v2.c3p0.ComboPooledDataSource;
public class C3P0Utils {
private static ComboPooledDataSource dataSource = new ComboPooledDataSource();
public static DataSource getDataSource() {
return dataSource;
}
public static Connection getConnection() {
try {
return dataSource.getConnection();
} catch (SQLException e) {
throw new RuntimeException(e);
}
}
}
使用C3P0和DBUtils
标签:mysql jdbc port default max encoding image .com vax