Hibernate中使用C3P0连接池

WEB项目中可以使用Tomcat中的连接池,需要在tomcat文件中进行配置,也可以使用自定义的的连接池,自定义连接池需要实现org.hibernate.connection.ConnectionProvider接口,并且在Hibernate配置文件中设置hibernate.connection.provider_classs属性.
还可以使用C3P0连接池,下面说明如何使用C3P0连接池.

首先在项目中配置Hibernate,然后在项目中加入C3P0的API(jar包).

这两个jar包在下载下来的Hibernate资源的lib -> c3p0目录下.

然后在hibernate.cfg.xml配置文件中进行配置:

 1 <!-- c3p0连接池设置 -->
 2         <property name="connection.provider_class">
 3             org.hibernate.service.jdbc.connections.internal.C3P0ConnectionProvider
 4         </property>
 5         <property name="hibernate.c3p0.min_size">10</property>
 6         <property name="hibernate.c3p0.max_size">20</property>
 7         <property name="hibernate.c3p0.timeout">360</property>
 8         <property name="hibernate.c3p0.max_statements">25</property>
 9         <property name="hibernate.c3p0.idle_test_period">120</property>
10         <property name="hibernate.c3p0.acquire_increment">2</property>
原文地址:https://www.cnblogs.com/hanyuan/p/2584364.html