Hibernate连接池的使用
Hibernate中有内置的连接池,当我们配置好连接参数后实际上采用的就是默认的的内置连接池,且最大连接数量为1。
<!-- JDBC connection pool (use the built-in) -->
<property name="connection.pool_size">1</property>
然而这种默认的内置连接池性能并不好,我们可以采用已经集成到Hibernate中的第三方的连接池C3P0。
在 Hibernate.cfg.xml 中配置 c3p0 连接池:
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<!-- Database connection settings -->
<property name="connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="connection.url">jdbc:mysql://localhost:3306/learning?useSSL=true</property>
<property name="connection.username">root</property>
<property name=