加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

使用PostgreSQL JDBC连接池

发布时间:2020-12-13 16:31:16 所属栏目:百科 来源:网络整理
导读:最近我从 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.post
最近我从 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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读