Results 1 to 4 of 4
  1. #1
    Join Date
    Jan 2003
    Location
    LA, CA, USA
    Posts
    2

    Unhappy Unanswered: Connection.isClosed() working in mysql-connector-java-3.0.4?

    mysql-connector-java-3.0.4-gamma-bin.jar.

    It appears that Connection.isClosed() may not be detecting closed connection in this latest driver. My connection pool manager is unable to detect the closed state caused by database restarts, or power outages (happens to me occasionaly) :-), and so us returning effectively null connections to my Statements.

    Anyone else confirmed this yet?

  2. #2
    Join Date
    Jan 2003
    Posts
    1
    isClosed() was re-written to comply with the JDBC spec.

    It only returns true when you have called .close() on a connection.

    Your connection pool should issue a 'ping' type query to test whether or not the connection is still valid.

  3. #3
    Join Date
    Jan 2003
    Location
    LA, CA, USA
    Posts
    2
    I accept that, not internally testing the connection state is permissable behavior, based on reading the API section for isClosed(), but I might also argue that it is "under-achieving", because although the API allows for not actually testing for the connection being closed ---it also does not explicitly say that isClosed *should not* test for a broken connection. It seems to leave it at the discretion of the driver vendor.

    In other words, the spec wouldnt be broken if the driver did or (did not) test the actual connection, right?

    The main reason I'd argue that the driver's isClosed should internally do the ping is that the ping query is going to be (somewhat) database dependent (but I'm no expert on this topic), and so should be abstracted into the driver.

    I do know that some other (albeit primitive) databases do not allow table-less query grammar like "select 'connected'", so there is no universal (non-abstract) 'ping' query by my reckoning (though I'm definately open to advise). I'd prefer not to put a 'ping' query into my connection pool.

    I also realize that there is a performance penalty for the driver to do a 'query' test. So, cant the state be checked instead inside of perhaps StandardSocketFactory via some Socket methods; isConnected(), isClosed()? This sounds much more efficient.

    Humbly, ken

  4. #4
    Join Date
    Mar 2003
    Location
    SWEDEN
    Posts
    1
    I use the following code to test a jdbc connection, it's working
    fine so far and it's fairly simple and not to consuming.

    boolean testConnection(Connection conn)
    {
    try
    {
    conn.createStatement().close();
    return true;
    }
    catch (Throwable exc)
    {
    return false;
    }
    }

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •