Thread

  1. JDBC: connection.isClosed() doesnt throw exception

    PostgreSQL Bugs List <pgsql-bugs@postgresql.org> — 2000-12-08T15:56:40Z

    andre levy (andre@freever.com) reports a bug with a severity of 2
    The lower the number the more severe it is.
    
    Short Description
    JDBC: connection.isClosed() doesnt throw exception
    
    Long Description
    connection.isClosed() doesn't throw an SQLException if "a database access error occurs". (cf 
    http://java.sun.com/j2se/1.3/docs/api/java/sql/Connection.html#isClosed())
    
    this means that if connection to db is closed, or worse, if db is down, I can't know it until I actually try to send a request!
    
    Sample Code
    This piece of code helps me to recover from a db restart without restarting my service...
    
      private Statement getStatement() throws SQLException {
        Statement stmt = null;
    
        try {
          boolean closed = m_connection.isClosed();
    
          if (closed)
           openDb();
        } catch(SQLException e) {
            closeDb();
            openDb();
        }
    
        stmt = m_connection.createStatement();
    
        return stmt;
      } // getStatement
    
    
    No file was uploaded with this report