According to section 11.1 of the JDBC 2.1 specification:“The Connection.isClosed() method is only guaranteed to return true after Connection.close() has been called. Connection.isClosed() cannot be called, in general, to determine if a database connection is valid or invalid. A typical client can determine that a connection is invalid by catching the exception that is thrown when an operation is attempted.”jConnect offers a default interpretation of the isClosed() method that is different from the behavior that is defined in the spec. When you call Connection.isClosed(), jConnect will first check if Connection.close() has been called on this connection. If close() has been called, jConnect will return true for isClosed().However, if Connection.close() has not been called, jConnect will next try to execute the sp_mda stored procedure on the database. The sp_mda stored procedure is part of the standard metadata that jConnect users must install when they use jConnect with a database.The purpose of calling sp_mda is so that jConnect can try to execute a procedure that is known (or at least, expected) to reside on the database server. If the stored procedure executes normally, then jConnect returns false for isClosed() because we have verified that the database Connection is valid and working. However, if the call to sp_mda results in a SQLException being thrown, jConnect catches the exception and returns true for isClosed() because it appears that there is something wrong with the Connection.If you wish to force jConnect to more closely follow the standard JDBC behavior for isClosed(), you can do so by setting the IS_CLOSED_TEST connection property to the special value ‘INTERNAL’. The INTERNAL setting means that jConnect will return true for isClosed() only when Connection.close() has been called, or when jConnect has detected an IOException that has disabled the Connection.You can also specify a query other than sp_mda to use when isClosed() is called. For example, if you wanted jConnect to try a select 1 when isClosed() was called, you could set the IS_CLOSED_TEST connection property to select 1.
Copyright © 2003. Sybase Inc. All rights reserved. |
![]() |