采用C3P0管理Hibernate的JDBC连接池
第一步,工程内导入C3P0包
第二步,修改Hibernate配置文件
添加以下代码
<!-- 配置c3p0连接池(解决MySQL空闲8小时自动断开问题)-->
<property name="hibernate.connection.provider_class">org.hibernate.connection.C3P0ConnectionProvider</property>
<property name="hibernate.c3p0.acquireIncrement">2</property>
<property name="hibernate.c3p0.checkoutTimeout">3000</property>
<property name="hibernate.c3p0.idleConnectionTestPeriod">2000</property>
<property name="hibernate.c3p0.maxIdleTime">4000</property>
<property name="hibernate.c3p0.maxPoolSize">60</property>
<property name="hibernate.c3p0.minPoolSize">1</property>
<property name="hibernate.c3p0.maxStatements">0</property>
<property name="hibernate.c3p0.validate">true</property>
<property name="hibernate.c3p0.testConnectionOnCheckout">true</property>