문제

I have an SQL query executed by:

ResultSet resultSet = preparedStatement.executeQuery();

while( resultSet.next() ){
     // do some stuff
}

Is there a way to stop the execution and do some code after let's say 2 minutes of execution?

Thanks

도움이 되었습니까?

해결책

You can set a timeout on executing a query. SQLException will be thrown if the query doesn't complete in time and times out:

preparedstatement.setQueryTimeout(seconds);
ResultSet resultSet = preparedStatement.executeQuery();

while( resultSet.next() ){
     // do some stuff
}

Have a look at setQueryTimeout documentation

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top