Java 调用executeUpdate()后超时
我在Java程序中有以下场景:Java 调用executeUpdate()后超时,java,jdbc,timeout,connection-timeout,Java,Jdbc,Timeout,Connection Timeout,我在Java程序中有以下场景: ... try // 1 PreparedStatement pstmt1 = conn.getPreparedStatement("SQL QUERY"); pstmt1.setQueryTimeout(1); pstm.executeUpdate(); System.out.println("1 executed"); // 2 PreparedStatement pstmt2 = conn.getPrepared
...
try
// 1
PreparedStatement pstmt1 = conn.getPreparedStatement("SQL QUERY");
pstmt1.setQueryTimeout(1);
pstm.executeUpdate();
System.out.println("1 executed");
// 2
PreparedStatement pstmt2 = conn.getPreparedStatement("SQL QUERY");
pstmt2.setQueryTimeout(1);
pstmt2.executeUpdate();
System.out.println("2 executed");
// 3
PreparedStatement pstmt3 = conn.getPreparedStatement("SQL QUERY");
pstmt3.setQueryTimeout(1);
pstmt3.executeUpdate();
System.out.println("3 executed");
catch(Exception e){
e.printStackTrace();
}
...
如果在第一次调用executeUpdate()之后,我“拔下电缆”,并且与数据库的连接丢失。我如何告诉程序只等待1秒,如果没有响应,则立即进入捕获
现在发生的情况是,程序在该点(第一个executeUpdate(),在输出“1 executed”)后卡住
方法pstmt.setQueryTimeout(1)似乎不起作用
我已经在服务器的连接池属性上设置了10秒的连接超时时间
几分钟(半小时)后,我得到以下错误(预期错误):
非常感谢您的帮助。如果您可以将代码包装成可调用的
,,我建议您使用。它正是为此目的而设计的。如果您可以将代码包装成可调用的,,我建议使用。它正是为此而设计的。并非所有驱动程序都支持查询超时。但即使他们这样做了:查询超时并不是为了检测网络超时。最有可能的选项,如查询超时,将由数据库服务器处理(即:请求服务器的驱动程序:如果查询时间超过xxx,则中止查询),或者驱动程序和/或服务器根本不支持查询
套接字超时的级别要低得多,大多数驱动程序对此都有连接属性设置(因此超时、套接字超时等)。并非所有驱动程序都支持查询超时。但即使他们这样做了:查询超时并不是为了检测网络超时。最有可能的选项,如查询超时,将由数据库服务器处理(即:请求服务器的驱动程序:如果查询时间超过xxx,则中止查询),或者驱动程序和/或服务器根本不支持查询
套接字超时的级别要低得多,大多数驱动程序都会为此设置连接属性(所以超时、套接字超时等)。如何获得连接?从池(或)在每次呼叫时创建连接?我在每次呼叫时创建连接。我进行JNDI查找,并从获得的数据源获得连接。您是如何获得连接的?从池(或)在每次呼叫时创建连接?我在每次呼叫时创建连接。我进行了JNDI查找,从获得的数据源中获得了连接。非常感谢您的回复。这是一篇关于JDBC超时的内容丰富的文章。非常感谢您的回复。这是一篇关于JDBC超时的内容丰富的文章。
The Connection Manager received a fatal connection error from the Resource Adapter for resource jdbc/JNDI_BD1. The exception which was received is com.ibm.websphere.ce.cm.StaleConnectionException: [jcc][t4][2030][11211][3.58.82] A communication error occurred during operations on the connection's underlying socket, socket input stream, or socket output stream. Error location: Reply.fill(). Message: No route to host. ERRORCODE=-4499, SQLSTATE=08001:com.ibm.db2.jcc.am.io: [jcc][t4][2030][11211][3.58.82] A communication error occurred during operations on the connection's underlying socket, socket input stream, or socket output stream. Error location: Reply.fill(). Message: No route to host. ERRORCODE=-4499, SQLSTATE=08001:java.net.SocketException: No route to host