经过一个周末的折腾,终于找到了hibernate中使用数据库连接池的解决方案。
从网上google了一下,发现大致有三种可以实施的解决方案:
1、使用hibernate自带的连接池;
2、使用c3po包的连接池功能;
3、使用Proxool包的连接池功能;
第一种方案,就是在myeclipse产生的hibernate.cfg.xml中添加一个属性:
<property name="connection.pool_size">20</property>
第二种方案是:
xhtml代码
- <property name="myeclipse.connection.profile">test</property>
- <property name="connection.driver_class">com.microsoft.jdbc.sqlserver.SQLServerDriver</property>
- <property name="connection.url">jdbc:microsoft:sqlserver://localhost:1433;databasename=test</property>
- <property name="connection.username">sa</property>
- <property name="connection.password">123</property>
- <property name="c3p0.min_size">2</property>
- <property name="c3p0.max_size">10</property>
- <property name="c3p0.timeout">1800</property>
- <property name="c3p0.acquireRetryAttempts">4</property>
- <property name="c3p0.acquireIncrement">1</property>
- <property name="c3p0.idleConnectionTestPeriod">36000</property>
- <property name="c3p0.initialPoolSize">2</property>
- <property name="c3p0.maxPoolSize">10</property>
- <property name="c3p0.maxIdleTime">1200</property>
- <property name="c3p0.maxStatements">30</property>
- <property name="c3p0.minPoolSize">2</property>
- <property name="connection.provider_class">org.hibernate.connection.C3P0ConnectionProvider</property>