Default: none Assuming the OP wants a Java answer: As of JDBC3 / Java 6 there's the is Valid() method which should be used rather than inventing one's own method.The implementer of the driver is required to execute some sort of query against the database when this method id called.My intention would be to programmatically determine a statement I can use based on my database provider configuration.My SQL also supports this for compatibility reasons, but not all databases do.
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?
You - as a mere JDBC user - do not have to know or understand what this query is.
All you have to do is to trust that the creator of the JDBC driver has done his/her work properly.
Famous connection pools, like Hikari CP, still have a config parameter for specifying a test query but strongly discourage to use it: 🔠connection Test Query If your driver supports JDBC4 we strongly recommend not setting this property.
This is for "legacy" databases that do not support the JDBC4 Valid() API.