public abstract class QueryValidator extends Object implements ConnectionValidator
ConnectionValidator implementation that validates
database connections by issuing a SQL query.
To create a simple ConnectionValidator implementation which validates using a SQL query, extend this class and implement the abstract methods.
For example, the getQueryString() method could be implemented to
return the string:
SELECT * FROM test WHERE test_id < 10;
This would cause this SQL query to be issued to the database whenever
a connection needs validating. If the query causes a SQLException
to be thrown then the validation automatically fails.
If the query completes successfully, the generated ResultSet
is then passed to the checkResults(ResultSet) method.
This class is provided as a convenience for providing connection validation.
| Constructor and Description |
|---|
QueryValidator() |
| Modifier and Type | Method and Description |
|---|---|
abstract boolean |
checkResults(ResultSet results)
Checks the results of the SQL query to see if it indicates a valid connection.
|
abstract String |
getQueryString()
Returns the SQL query string to be issued to the database.
|
boolean |
isValid(Connection con)
Determines whether the specified connection is good to use.
|
public final boolean isValid(Connection con) throws SQLException
isValid in interface ConnectionValidatorcon - Connection instance to check for validitySQLException - if the connection is invalidpublic abstract String getQueryString()
public abstract boolean checkResults(ResultSet results) throws SQLException
results - ResultSet instance produced from SQL querySQLException - if checking the results throws such an exceptionCopyright © 2016. All rights reserved.