如何使 java.sql.ResultSet 超时
由于某种原因,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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
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.