简体   繁体   English

如何超时java.sql.ResultSet

[英]How to Timing out java.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 . 由于某些原因,PL / SQl光标被挂起,这使我的应用程序在尝试遍历ResultSet时挂起。

Is there a way to handle this, like timing out the resultset if the database hangs? 有没有一种方法可以解决此问题,例如在数据库挂起时使结果集超时?

There is a setQueryTimeout(int) on the java.sql.Statement interface. java.sql.Statement接口上有一个setQueryTimeout(int)。 You should call it before invoking the executeQuery(). 您应该在调用executeQuery()之前先调用它。

You can also asynchronously cancel a running query by calling cancel() on the Statement too. 您也可以通过在Statement上调用cancel()来异步取消正在运行的查询。

Edit: Oracle jdbc driver version 6 supports these methods for sure, as I'm using it in one of my projects. 编辑: Oracle jdbc驱动程序版本6肯定支持这些方法,因为我在我的一个项目中正在使用它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM