java - oracle jdbc瘦连接中连接空闲超过5分钟时连接关闭
问题描述
此代码片段执行查询,然后程序休眠 5 分钟,然后为 isValid 方法返回 false。使用 jdbc 瘦客户端。db 上的 max_idle_time 设置为 0。对于本地计算机数据库实例,连接不会关闭。所以我猜,它一定和我的网络有关。任何帮助将不胜感激。
package com.oracle.jdbc.test;
import java.sql.*;
public class JDBCTest {
public static void main(String args[]){
try{
//step1 load the driver class
Class.forName("oracle.jdbc.driver.OracleDriver");
//step2 create the connection object
Connection con=DriverManager.getConnection(
"jdbc:oracle:thin:@****","****","****");
//step3 create the statement object
Statement stmt=con.createStatement();
//step4 execute query
ResultSet rs=stmt.executeQuery("select 1 from dual");
while(rs.next())
System.out.println(rs.getInt(1));
//step5 close the connection object
Thread.sleep(300000);
System.out.println(con.isValid(1));
stmt.executeQuery("select 1 from dual");
}catch(Exception e){ System.out.println(e);}
}
}
enter code here
解决方案
推荐阅读
- vba - 有没有办法为 Word VBA 组合框文本条目的一部分添加粗体样式?
- asp.net - ASP 文本框标签字体颜色
- amazon-web-services - AWS/EKS:从 ALB 获取频繁的 504 网关超时错误
- android - 如何在 AccessibilityService 中跟踪长按键事件?
- mysql - 将 SQL 转换为 PostgreSQL
- powershell - SharePoint Get-PnPListItem -查询
- ngrx - 错误 TS2345:“对象”类型的参数不可分配给“用户”类型的参数。(NgRx)
- sql - 从另一个表更新 SQL - 大搞砸了
- php - 如何从laravel中的字符串中提取所有#Tags和用户标签?
- windows - 如何防止以 process:Command 启动的 Windows 程序打开弹出窗口?