Many database connection pooling libraries provide the ability to test their SQL connections for idleness. For example, the JDBC pooling library c3p0 has a property called preferredTestQuery
, which gets executed on the connection at configured intervals. Similarly, Apache Commons DBCP has validationQuery
.
Many example queries I've seen are for MySQL and recommend using SELECT 1;
as the value for the test query. However, this query doesn't work on some databases (e.g. HSQLDB, for which SELECT 1
expects a FROM
clause).
Is there a database-agnostic query that's equivalently efficient but will work for all SQL databases?
Edit:
If there's not (which seems to be the case), can somebody suggest a set of SQL queries that will work for various database providers? My intention would be to programmatically determine a statement I can use based on my database provider configuration.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…