1. pom.xml 导入hibernate-c3p0 架包
注意: hibernate-c3p0 架包中包含 c3p0 ,则不需要单独引入 c3p0
org.hibernate
hibernate-c3p0
5.3.4.Final
2. 配置 c3p0 核心信息
更多配置信息:
com.mysql.jdbc.Driver
jdbc:mysql://localhost:3306/test_hibernate5
root
123456
org.hibernate.dialect.MySQL5InnoDBDialect
true
true
update
org.hibernate.c3p0.internal.C3P0ConnectionProvider
20
5
2000
10
2000
10
30
100
3. 测试 Hibernate 是否使用 c3p0 连接池
输出:com.mchange.v2.c3p0.impl.NewProxyConnection@6f0628de [wrapping: com.mysql.jdbc.JDBC4Connection@797cea6f]
@Test
public void test() {
session.doWork(new Work() {
public void execute(Connection arg0) throws SQLException {
System.out.println(arg0);
}
});
}