经过一个周末的折腾,终于找到了hibernate中使用数据库连接池的解决方案。
从网上google了一下,发现大致有三种可以实施的解决方案:
1、使用hibernate自带的连接池;
2、使用c3po包的连接池功能;
3、使用Proxool包的连接池功能;
第一种方案,就是在myeclipse产生的hibernate.cfg.xml中添加一个属性:
20
第二种方案是:
test
com.microsoft.jdbc.sqlserver.SQLServerDriver
jdbc:microsoft:sqlserver://localhost:1433;databasename=test
sa
123
2
10
1800
4
1
36000
2
10
1200
30
2
org.hibernate.connection.C3P0ConnectionProvider
第三中方案是Proxool:
在hibernate.cfg.xml中添加:
org.hibernate.connection.ProxoolConnectionProvider
DBPool
Proxool.xml
org.hibernate.dialect.SQLServerDialect
false
然后再添加一个Proxool.xml文件:
DBPool
jdbc:microsoft:sqlserver://localhost:1433;databasename=test
com.microsoft.jdbc.sqlserver.SQLServerDriver
10
这个三种方案,我都可以配置成功,可是,郁闷的是,这三种方案,都比我不用连接池的数据要慢,可能是我的测试不准确吧?我只做了连续100000次的数据插入操作