怎样在hibernate中使用数据库连接池
1个回答
展开全部
从网上google了一下,发现大致有三种可以实施的解决方案:
1、使用hibernate自带的连接池;
2、使用c3po包的连接池功能;
3、使用Proxool包的连接池功能;
第一种方案,就是在myeclipse产生的hibernate.cfg.xml中添加一个属性:
<property >20</property>
第二种方案是:
<property >test</property>
<property >com.microsoft.jdbc.sqlserver.SQLServerDriver</property>
<property >jdbc:microsoft:sqlserver://localhost:1433;databasename=test</property>
<property >sa</property>
<property >123</property>
<property >2</property>
<property >10</property>
<property >1800</property>
<property >4</property>
<property >1</property>
<property >36000</property>
<property >2</property>
<property >10</property>
<property >1200</property>
<property >30</property>
<property >2</property>
<property >org.hibernate.connection.C3P0ConnectionProvider</property>
第三中方案是Proxool:
在hibernate.cfg.xml中添加:
<!-- Proxool Database connection settings -->
<property >org.hibernate.connection.ProxoolConnectionProvider</property>
<property >DBPool</property>
<property >Proxool.xml</property>
<property >org.hibernate.dialect.SQLServerDialect</property>
<property >false</property>
然后再添加一个Proxool.xml文件:
<?xml version="1.0" encoding="UTF-8"?>
<!-- the proxool configuration can be embedded within your own application's.
Anything outside the "proxool" tag is ignored. -->
<something-else-entirely>
<proxool>
<alias>DBPool</alias>
<driver-url>jdbc:microsoft:sqlserver://localhost:1433;databasename=test</driver-url>
<driver-class>com.microsoft.jdbc.sqlserver.SQLServerDriver</driver-class>
<driver-properties>
<property value="sa"/>
<property value="123"/>
</driver-properties>
<maximum-connection-count>10</maximum-connection-count>
</proxool>
</something-else-entirely>
1、使用hibernate自带的连接池;
2、使用c3po包的连接池功能;
3、使用Proxool包的连接池功能;
第一种方案,就是在myeclipse产生的hibernate.cfg.xml中添加一个属性:
<property >20</property>
第二种方案是:
<property >test</property>
<property >com.microsoft.jdbc.sqlserver.SQLServerDriver</property>
<property >jdbc:microsoft:sqlserver://localhost:1433;databasename=test</property>
<property >sa</property>
<property >123</property>
<property >2</property>
<property >10</property>
<property >1800</property>
<property >4</property>
<property >1</property>
<property >36000</property>
<property >2</property>
<property >10</property>
<property >1200</property>
<property >30</property>
<property >2</property>
<property >org.hibernate.connection.C3P0ConnectionProvider</property>
第三中方案是Proxool:
在hibernate.cfg.xml中添加:
<!-- Proxool Database connection settings -->
<property >org.hibernate.connection.ProxoolConnectionProvider</property>
<property >DBPool</property>
<property >Proxool.xml</property>
<property >org.hibernate.dialect.SQLServerDialect</property>
<property >false</property>
然后再添加一个Proxool.xml文件:
<?xml version="1.0" encoding="UTF-8"?>
<!-- the proxool configuration can be embedded within your own application's.
Anything outside the "proxool" tag is ignored. -->
<something-else-entirely>
<proxool>
<alias>DBPool</alias>
<driver-url>jdbc:microsoft:sqlserver://localhost:1433;databasename=test</driver-url>
<driver-class>com.microsoft.jdbc.sqlserver.SQLServerDriver</driver-class>
<driver-properties>
<property value="sa"/>
<property value="123"/>
</driver-properties>
<maximum-connection-count>10</maximum-connection-count>
</proxool>
</something-else-entirely>
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询