public class SimpleQueryValidator extends QueryValidator
ConnectionValidator implementation that validates database
connections by issuing a SQL query, and simply checking if the query
succeeded or failed.
By default it does not check if any results are returned.
This class is provided as a convenience for providing connection validation.
| Constructor and Description |
|---|
SimpleQueryValidator(String query)
Creates a new
SimpleQueryValidator instance using the
specified SQL query string. |
SimpleQueryValidator(String query,
boolean checkHasResults)
Creates a new
SimpleQueryValidator instance using the
specified SQL query string. |
| Modifier and Type | Method and Description |
|---|---|
boolean |
checkResults(ResultSet results)
Checks the results of the SQL query to see if it indicates a valid connection.
|
String |
getQueryString()
Returns the SQL query string to be issued to the database.
|
isValidpublic SimpleQueryValidator(String query)
SimpleQueryValidator instance using the
specified SQL query string. The created instance will not check for
existence of returned results, only that the query succeeded.query - SQL query to issue for validationpublic SimpleQueryValidator(String query, boolean checkHasResults)
SimpleQueryValidator instance using the
specified SQL query string.query - SQL query to issue for validationcheckHasResults - whether to check if any results are returnedpublic String getQueryString()
getQueryString in class QueryValidatorpublic boolean checkResults(ResultSet results) throws SQLException
return checkHasResults ? results.next() : true;
such that if results-checking was specified when the instance was created
then the connection is only validated if some results are returned,
otherwise the simply fact of the statement being executed successfully
is used for validation.checkResults in class QueryValidatorresults - ResultSet instance produced from SQL querySQLException - if checking the results throws such an exceptionCopyright © 2014. All rights reserved.