Skip to content

Commit

Permalink
added isValid implementation from Luis Flores
Browse files Browse the repository at this point in the history
  • Loading branch information
Dave Cramer committed Jan 19, 2012
1 parent 6bd8784 commit 773f8e4
Showing 1 changed file with 23 additions and 3 deletions.
26 changes: 23 additions & 3 deletions org/postgresql/jdbc4/AbstractJdbc4Connection.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Copyright (c) 2004-2011, PostgreSQL Global Development Group
*
* IDENTIFICATION
* $PostgreSQL: pgjdbc/org/postgresql/jdbc4/AbstractJdbc4Connection.java,v 1.11 2011/03/31 06:25:42 jurka Exp $
* $PostgreSQL: pgjdbc/org/postgresql/jdbc4/AbstractJdbc4Connection.java,v 1.12 2011/08/02 13:49:23 davecramer Exp $
*
*-------------------------------------------------------------------------
*/
Expand Down Expand Up @@ -117,8 +117,28 @@ private static void appendArray(StringBuffer sb, Object elements)
public boolean isValid(int timeout) throws SQLException
{
checkClosed();
throw org.postgresql.Driver.notImplemented(this.getClass(), "isValid(int)");
}
if (timeout < 0) {
throw new PSQLException(GT.tr("Invalid timeout ({0}<0).", timeout), PSQLState.INVALID_PARAMETER_VALUE);
}
boolean valid = false;
Statement stmt = null;
try {
if (!isClosed()) {
stmt = createStatement();
stmt.setQueryTimeout( timeout );
stmt.executeQuery( "SELECT 1" );
valid = true;
}
}
catch ( SQLException e) {
getLogger().log(GT.tr("Validating connection."),e);
}
finally
{
if(stmt!=null) try {stmt.close();}catch(Exception ex){}
}
return valid;
}

public void setClientInfo(String name, String value) throws SQLClientInfoException
{
Expand Down

0 comments on commit 773f8e4

Please sign in to comment.