java - PreparedStatement.setQueryTimeout() 不抛出异常

标签 java database exception

我试图将查询超时设置为 5 秒,但 5 秒后没有捕获到异常

        preparedStatement.setQueryTimeout(5);
        try{
            return  preparedStatement.executeQuery();
        }catch(SQLException e){
            throw new CustomException(CustomErrorCode.RESPONSE_TIME_OUT,"");
        }
      ```

最佳答案

超过超时时,它应该抛出SQLTimeoutException,而不是常规的SQLException

See more here

关于java - PreparedStatement.setQueryTimeout() 不抛出异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62046137/

相关文章:

Java单线程执行和cpu缓存

MySQL:mysqlcheck 占用太多磁盘空间来执行操作

java - 如何手动退出 while 循环 (java)

添加到方法的 c++ 自定义异常给出错误

java - 如何以编程方式覆盖方法或 bean 的 Glassfish 超时配置?

java - 使用java安排任务

database - 基于语言的 URL 和数据库路由

python - 我怎么知道在 Python 中捕获哪些异常

java - 我们可以使用 volley 库在删除请求中发送带有 x-www-url-form-encoded 的正文吗?

database - 当我在 PostgreSQL 中创建新服务器时连接被拒绝