Hello,
I develop some java desktop apps used in laptops. The apps use remote postgresql databases. To deal with sleep/interrupted connection issues I want to use JDBC4 isValid(int) method. Current driver didn't implemented it, so here it is a sample implementation (to replace in AbstractJdbc4Connection.java file):
public boolean isValid(int timeout) throws SQLException
{
if (timeout < 0) {
throw new PSQLException(GT.tr("Invalid timeout ({0}<0).", timeout), PSQLState.INVALID_PARAMETER_VALUE);
}
boolean valid = false;
try {
if (!isClosed()) {
Statement stm = createStatement();
stm.setQueryTimeout( timeout );
stm.executeQuery( "SELECT 1" ).close();
valid = true;
}
}
catch ( SQLException e) {
getLogger().log(GT.tr("Validating connection."),e);
}
return valid;
}
That's it.
Thanks,
Luis Flores