gpt4 book ai didi

postgresql - 使用 PostgreSQL JDBC 的连接池

转载 作者:行者123 更新时间:2023-11-29 11:14:44 27 4
gpt4 key购买 nike

最近我从 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 中是否有任何我不知道的池化DataSource,或者应该是什么我改用?我在 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.PPGoolingDataSource
这是一个例子: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

关于postgresql - 使用 PostgreSQL JDBC 的连接池,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19203989/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com