Oracle DB:java.sql.SQLException:关闭连接

发布于 2024-11-25 08:05:50 字数 715 浏览 0 评论 0原文

java.sql.SQLException 的原因:来自 Oracle 的关闭连接?

java.sql.SQLException:关闭连接 在 oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:112) 在 oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:146) 在 oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:208) 在 oracle.jdbc.driver.PhysicalConnection.commit(PhysicalConnection.java:1131) 在 oracle.jdbc.OracleConnectionWrapper.commit(OracleConnectionWrapper.java:117)

我们从故障转移数据库连接中收到此错误。我们也对其他数据库使用相同的代码。但只有一个数据库出现这个问题。这是因为连接可能由于长时间不活动而超时,而我们正在尝试使用它吗?如果您需要更多详细信息,请告诉我...

AbandonedConnectionTimeout 设置为 15 分钟 InactivityTimeout 设置为 30 分钟

Reasons for java.sql.SQLException: Closed Connection from Oracle??

java.sql.SQLException: Closed Connection
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:112)
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:146)
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:208)
at oracle.jdbc.driver.PhysicalConnection.commit(PhysicalConnection.java:1131)
at oracle.jdbc.OracleConnectionWrapper.commit(OracleConnectionWrapper.java:117)

We are getting this error from the fail over database connection. We use the same code for other databases as well. But seeing this issue with only one of the databases. Is this because the connection might have timeout due to long inactivity period and we are trying to use that? Pls let me know if you need more details...

AbandonedConnectionTimeout set to 15 mins
InactivityTimeout set to 30 mins

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

櫻之舞 2024-12-02 08:05:50

这意味着连接在某个时刻已成功建立,但是当您尝试在那里提交时,连接不再打开。您提到的参数听起来像是连接池设置。如果是这样,则它们与此问题无关。最可能的原因是您和数据库之间的防火墙在一定的空闲时间后终止连接。最常见的修复方法是让连接池在检出连接时运行验证查询。这将立即识别并驱逐死连接,确保您只从池中获得良好的连接。

It means the connection was successfully established at some point, but when you tried to commit right there, the connection was no longer open. The parameters you mentioned sound like connection pool settings. If so, they're unrelated to this problem. The most likely cause is a firewall between you and the database that is killing connections after a certain amount of idle time. The most common fix is to make your connection pool run a validation query when a connection is checked out from it. This will immediately identify and evict dead connnections, ensuring that you only get good connections out of the pool.

初与友歌 2024-12-02 08:05:50

您必须验证连接。

如果您使用 Oracle,则很可能使用 Oracle 的 通用连接池 。以下假设您这样做。

验证连接的最简单方法是告诉 Oracle 在借用连接时必须验证该连接。这可以通过以下方式完成

pool.setValidateConnectionOnBorrow(true);

,但仅当您保持连接很短一段时间时它才有效。如果您借用连接的时间较长,则连接很可能在您持有期间断开。在这种情况下,您必须显式验证连接,

if (connection == null || !((ValidConnection) connection).isValid())

请参阅 Oracle 文档 了解更多详情。

You have to validate the connection.

If you use Oracle it is likely that you use Oracle´s Universal Connection Pool. The following assumes that you do so.

The easiest way to validate the connection is to tell Oracle that the connection must be validated while borrowing it. This can be done with

pool.setValidateConnectionOnBorrow(true);

But it works only if you hold the connection for a short period. If you borrow the connection for a longer time, it is likely that the connection gets broken while you hold it. In that case you have to validate the connection explicitly with

if (connection == null || !((ValidConnection) connection).isValid())

See the Oracle documentation for further details.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文