1. 程序內部啟動 c3p0 連接池。
配置方式如下:連接池的支持(注:需要c3p0的類庫支持)
<property name="hibernate.connection.driver_class" value="org.postgresql.Driver" />
<property name="hibernate.connection.url" value="jdbc:postgresql://xxxxx/xxxx" />
<property name="hibernate.connection.username" value="xxxxx" />
<property name="hibernate.connection.password" value="xxxx" />
<property name="hibernate.c3p0.min_size"
value="5"/>
<property name="hibernate.c3p0.max_size"
value="20"/>
<property name="hibernate.c3p0.timeout"
value="300"/>
<property name="hibernate.c3p0.max_statements"
value="50"/>
<property name="hibernate.c3p0.idle_test_period"
value="3000"/>
注: Hibernate根據 hibernate.c3p0.max_size 這個配置來識別是支持c3p0連接池<property name="hibernate.connection.url" value="jdbc:postgresql://xxxxx/xxxx" />
<property name="hibernate.connection.username" value="xxxxx" />
<property name="hibernate.connection.password" value="xxxx" />
<property name="hibernate.c3p0.min_size"
value="5"/>
<property name="hibernate.c3p0.max_size"
value="20"/>
<property name="hibernate.c3p0.timeout"
value="300"/>
<property name="hibernate.c3p0.max_statements"
value="50"/>
<property name="hibernate.c3p0.idle_test_period"
value="3000"/>
2. 引用外部連接池 (通過JNDI查找 DataSource資料)
需要配置方式如下:
<property name="hibernate.connection.datasource" value="java:comp/env/jdbc/qualitydb"/>
3. 通過 org.hibernate.connection.ProxoolConnectionProvider 創建
由
hibernate.proxool.xml
hibernate.proxool.properties
hibernate.proxool.existing_pool 三個配置一起來確定
4. DriverManager 創建直接連接方式
<property name="hibernate.connection.driver_class" value="org.postgresql.Driver" />
<property name="hibernate.connection.url" value="jdbc:postgresql://xxxxx/xxxx" />
<property name="hibernate.connection.username" value="xxxxx" />
<property name="hibernate.connection.password" value="xxxx" />
注: Hibernate根據 hibernate.connection.url這個來識別,由于在識別時,c3p0的優先級會高于DriverManger所以,與c3p0的配置不會沖突<property name="hibernate.connection.url" value="jdbc:postgresql://xxxxx/xxxx" />
<property name="hibernate.connection.username" value="xxxxx" />
<property name="hibernate.connection.password" value="xxxx" />
Good Luck!
Yours Matthew!