使用PostgreSQL JDBC连接池

前端之家收集整理的这篇文章主要介绍了使用PostgreSQL JDBC连接池前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
最近我从 here下载了Postgresql的JDBC驱动程序.
由于我使用的是Java 1.7 JVM,它的写法是:

If you are using the 1.6 or 1.7 JVM,then you should use the JDBC4
version.

我下载了JDBC4.问题在于它没有PoolingDataSource.
如果您获得JDBC3,可以使用org.postgresql.jdbc3.Jdbc3PoolingDataSource或
其他如here所见.

在JDBC4中有没有任何池数据源,我不知道,还是应该怎么做
我用吗我在JDBC4中发现的唯一的事情是PGPoolingDataSource,但我不是
如果我应该使用它,因为根据他们的Java文档消息:

Don’t use this if your server/middleware vendor provides a connection pooling implementation which interfaces with the Postgresql ConnectionPoolDataSource implementation!

使用org.postgresql.ds.PGPoolingDataSource
这是一个例子: http://jdbc.postgresql.org/documentation/head/ds-ds.html
我已经使用JDBC4驱动程序检查了这个例子,它工作正常.

然而在这个链接的文档中,由于它的局限性,他们不鼓励使用postgresql池数据源:

The pooling data-source implementation provided here is not the most feature-rich in the world. Among other things,connections are never closed until the pool itself is closed; there is no way to shrink the pool. As well,connections requested for users other than the default configured user are not pooled. Its error handling sometimes cannot remove a broken connection from the pool. In general it is not recommended to use the Postgresql˘ provided connection pool. Check your application server or check out the excellent jakarta commons DBCP project.

他们建议使用DBCP连接池:http://commons.apache.org/proper/commons-dbcp/
检查一下,它更好 – 只需下载库文件,将它们放在一个类中并导入到项目中,从上述链接的文档中包含如何在代码中使用的示例.
大多数(所有?)应用服务器实现自己的连接池,如果您正在使用应用程序服务器,这是最好的选择.
对于示例,Tomcat 7具有自己的连接池的实现,比DBCP更好,检查文档:http://tomcat.apache.org/tomcat-7.0-doc/jdbc-pool.html

原文链接:https://www.f2er.com/postgresql/191657.html

猜你在找的Postgre SQL相关文章