hibernate连接池Word下载.docx
《hibernate连接池Word下载.docx》由会员分享,可在线阅读,更多相关《hibernate连接池Word下载.docx(14页珍藏版)》请在冰豆网上搜索。
下面是Hibernate环境下几种常见的连接池配置:
1.Hibernate默认连接池
<
?
xmlversion='
1.0'
encoding='
UTF-8'
>
!
DOCTYPEhibernate-configuration
PUBLIC"
-//Hibernate/HibernateConfigurationDTD//EN"
"
hibernate-configuration>
session-factory>
—JDBC驱动程序-->
propertyname="
connection.driver_class"
com.mysql.jdbc.Driver<
/property>
--连接数据库的URL-->
connection.url"
jdbc:
mysql:
//localhost:
3306/schoolproject
connection.useUnicode"
true<
connection.characterEncoding"
UTF-8<
--连接的登录名-->
connection.username"
root<
—登录密码-->
connection.password"
--是否将运行期生成的SQL输出到日志以供调试-->
show_sql"
--指定连接的语言-->
dialect"
org.hibernate.dialect.MySQLDialect<
--映射Student这个资源-->
mappingresource="
com/wqbi/model/pojo/student.hbm.xml"
/>
/session-factory>
/hibernate-configuration>
2.C3P0连接配置
--登录密码-->
--C3P0连接池设定-->
p
hibernate.connection.provider_class"
org.hibernate.connection.C3P0ConnectionProvider
hibernate.c3p0.max_size"
20<
hibernate.c3p0.min_size"
5<
hibernate.c3p0.timeout"
120<
hibernate.c3p0.max_statements"
100<
hibernate.c3p0.idle_test_period"
hibernate.c3p0.acquire_increment"
2<
3.proxool连接池
(1)先写proxool的配置文件,文件名:
proxool.xml(一般放在与hibernate.cfg.xml文件在同一个目录中)本例配置的是MYSQL数据库,数据库的名字为schoolproject
xmlversion="
1.0"
encoding="
UTF-8"
--theproxoolconfigurationcanbeembeddedwithinyourownapplication'
s.
Anythingoutsidethe"
proxool"
tagisignored.-->
something-else-entirely>
proxool>
--连接池的别名-->
alias>
DBPool<
/alias>
--proxool只能管理由自己产生的连接-->
driver-url>
3306/schoolproject?
useUnicode=true&
amp;
characterEncoding=UTF8
/driver-url>
driver-class>
/driver-class>
driver-properties>
user"
value="
root"
/>
password"
/driver-properties>
--proxool自动侦察各个连接状态的时间间隔(毫秒),侦察到空闲的连接就马上回
收,超时的销毁-->
house-keeping-sleep-time>
90000<
/house-keeping-sleep-time>
--指因未有空闲连接可以分配而在队列中等候的最大请求数,超过这个请求数的
用户连接就不会被接受-->
maximum-new-connections>
/maximum-new-connections>
--最少保持的空闲连接数-->
prototype-count>
/prototype-count>
--允许最大连接数,超过了这个连接,再有请求时,就排在队列中等候,最大的
等待请求数由maximum-new-connections决定-->
maximum-connection-count>
/maximum-connection-count>
--最小连接数-->
minimum-connection-count>
10<
/minimum-connection-count>
/proxool>
/something-else-entirely>
(2)配置hibernate.cfg.xml文件
org.hibernate.connection.ProxoolConnectionProvider
hibernate.proxool.pool_alias"
hibernate.proxool.xml"
proxoolconf.xml<