Ludovic Maillet wrote:
> Hello again !
>
> How to know if a java.sql.connection is valid,
> without calling a select 1; ?
>
> (I'm working with Mysql-Connector)
>
> Thanks
> Ludovic
Ludovic,
That's the only way, i.e. issue a query. There is no JDBC standard way of determining connection validity, mostly because all vendors handle the entire processing path differently.
You might consider writing your application in such a way that it actually handles SQLExceptions, and attempts recovery for certain classes of errors, for example connections dying usually throw a SQLException with a SQLState of '08xxx'.
As a reminder 'isClosed()' _does_not_check_ for connection validity, as the JDBC spec states, it only returns true if Connection.close() has been called.
-Mark
Mark Matthews
Consulting Member Technical Staff - MySQL Enterprise Tools
Oracle
http://www.mysql.com/products/enterprise/monitor.html