如何使 java.sql.ResultSet 超时

发布于 2024-07-25 11:28:18 字数 114 浏览 2 评论 0原文

由于某种原因,PL/SQl 游标被挂起,这使得我的应用程序在尝试循环 ResultSet 时挂起。

有没有办法处理这个问题,比如如果数据库挂起则使结果集超时?

The PL/SQl cursor was getting hanged due to some reason, this makes my app to hang when try to loop through the ResultSet.

Is there a way to handle this, like timing out the resultset if the database hangs?

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

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

发布评论

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

评论(1

花开柳相依 2024-08-01 11:28:18

java.sql.Statement 接口上有一个 setQueryTimeout(int) 。 您应该在调用executeQuery() 之前调用它。

您还可以通过在 Statement 上调用 cancel() 来异步取消正在运行的查询。

编辑: Oracle jdbc 驱动程序版本 6 当然支持这些方法,因为我在我的一个项目中使用它。

There is a setQueryTimeout(int) on the java.sql.Statement interface. You should call it before invoking the executeQuery().

You can also asynchronously cancel a running query by calling cancel() on the Statement too.

Edit: Oracle jdbc driver version 6 supports these methods for sure, as I'm using it in one of my projects.

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