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()、出力「1execute」)の後でスタックします。
メソッドpstmt.setQueryTimeout(1)が機能していないようです。
サーバーの接続プールプロパティで接続タイムアウトを10秒に設定しました。
数分(30分)後、次のエラー(予想されるエラー)が発生します。
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
どんな助けでも大歓迎です。