In geronimo, there is GBean "org.apache.geronimo.connector.DatabaseInitializationGBean", which has an attribute to test a connection before executing the target sql.
A sample about how to use it, refer to http://cwiki.apache.org/GMOxDOC22/configuring-your-own-monitoring-plugin-datasource.html Hope this helpful! Good luck!
