Java – what is the best way to “Ping” a database through JDBC?
I tried to determine the best way to Ping the database through JDBC "Best" I mean fast and low cost For example, I have considered implementing this:
"SELECT 1 FROM DUAL"
But I believe the dual table is Oracle specific, and I need something more general
Note that connection has an isclosed () method, but Javadoc indicates that this cannot be used to test the validity of the connection
Solution
Yes, that is Oracle only, but there is no common method in JDBC
Most connection pool implementations have a configuration parameter in which you can specify the SQL to be used for Ping, thereby pushing responsibility to determine how to perform this operation to the user
This seems to be the best approach unless someone comes up with a small helper tool (of course, it excludes the use of potentially faster non SQL based methods, such as Oracle's internal ping function)