Re: connection valid ?
Posted by: Mark Matthews
Date: February 16, 2005 07:46AM

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


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 Matthews
Consulting Member Technical Staff - MySQL Enterprise Tools

Options: ReplyQuote

Written By
February 16, 2005 06:51AM
Re: connection valid ?
February 16, 2005 07:46AM

Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.