日期:2014-05-16  浏览次数:20403 次

Hibernate 连接池的三种配置方式:dbcp , c3p0 , proxool
Hibernate 连接池的三种配置方式:dbcp , c3p0 , proxool
URL的多种指定方式
连接池监控

上班第二天,看到公司的Hibernate配置文件在写法上,跟我以前的不一样,就去研究了哈,得出的结果如下。


在hibernate3.0中,已经不再支持dbcp了,hibernate的作者在hibernate.org中,
明确指出在实践中发现dbcp有BUG,在某些种情会产生很多空连接不能释放,
所以抛弃了对dbcp的支持。


1 =================== C3P0 配置 =============================

Xml代码
1.<?xml version="1.0" encoding="UTF-8"?> 
2.<!DOCTYPE hibernate-configuration PUBLIC  
3.  "-//Hibernate/Hibernate Configuration DTD 3.0//EN"  
4.  "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"> 
5.<hibernate-configuration> 
6.    <session-factory> 
7.    <!-- 配置事务实现方式 -->   
8.     <property name="transaction.factory_class"> 
9.       org.hibernate.transaction.JDBCTransactionFactory                               
10.     </property> 
11.     
12.    <!-- 配置JDBC里batch的大小 --> 
13.      <property name="jdbc.batch_size">50</property> 
14.      <property name="cache.use_second_level_cache">false</property> 
15.     
16.    <!-- 配置线程安全的session --> 
17.     <property name="current_session_context_class">thread</property> 
18.     
19.      <!-- 显示SQL --> 
20.      <property name="show_sql">true</property> 
21.      <property name="format_sql">true</property> 
22.       
23.      <!-- 配置数据库方言 --> 
24.      <property name="dialect">org.hibernate.dialect.Oracle9Dialect</property> 
25.       
26.      <!-- 配置数据库连接 --> 
27.      <property name="connection.driver_class">oracle.jdbc.driver.OracleDriver</property> 
28.      <property name="connection.username">0804</property> 
29.      <property name="connection.password">0804</property> 
30.      <property name="connection.url">jdbc:oracle:thin:@192.168.0.200:1521:orcl</property> 
31.      
32.      <!-- 配置连接池 --> 
33.      <property name="c3p0.max_size">2</property> 
34.      <property name="c3p0.min_size">2</property> 
35.      <property name="c3p0.timeout">5000</property> 
36.      <property name="c3p0.max_statements">100</property> 
37.      <property name="c3p0.idle_test_period">3000</property> 
38.      <property name="c3p0.acquire_increment">2</property> 
39.      <property name="c3p0.validate">false</property> 
40.       
41.   &nb