我在一個Java程序中的以下情形:超時()調用
...
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已執行」)後卡住了。
方法pstmt.setQueryTimeout(1)似乎不起作用。
我已經在服務器的連接池屬性上設置了10秒的連接超時時間。
經過大量分鐘(半小時),我得到以下錯誤(預期錯誤):
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
任何幫助是非常讚賞。
如何獲得連接?從池中(或)在每個呼叫上創建連接? – kosa
我在每個呼叫上創建連接。我做了JNDI查找,並從獲得的DataSource獲得連接。 – brokermq