How to detect stale connections?
843859Nov 9 2006 — edited Nov 13 2006'm working on an application that monitors tables on an AS/400 and transfers them in real time to a MySQL database. The application needs to be up 24X7. Once a week the AS400 is taken off line for about 15 minutes. When the AS/400 goes down I expect SQLExceptions to be thrown but instead my code seems to hang and no exceptions are thrown. My intention is to monitor for exceptions and eventually reconnect to the AS/400 when it is back up.
In the code sample below the connection is stale before the method is entered, but no exceptions are thrown and execution stops when at "resultSet = stmnt.executeQuery(sql);"
Any insights will be appreciated.
Relevant Code
public void setUpdatableResultSet(String sql) throws SQLException {
stmnt = connection.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
ResultSet.CONCUR_UPDATABLE);
resultSet = stmnt.executeQuery(sql);
}