我试图将查询超时设置为 5 秒,但 5 秒后没有捕获到异常
preparedStatement.setQueryTimeout(5);
try{
return preparedStatement.executeQuery();
}catch(SQLException e){
throw new CustomException(CustomErrorCode.RESPONSE_TIME_OUT,"");
}
```
最佳答案
超过超时时,它应该抛出SQLTimeoutException
,而不是常规的SQLException
。
关于java - PreparedStatement.setQueryTimeout() 不抛出异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62046137/