krummas / DrizzleJDBC

A BSD licensed JDBC driver for Drizzle and MySQL
BSD 3-Clause "New" or "Revised" License
31 stars 22 forks source link

Subsequent calls to Connection.close() should not throw an error and be ignored #32

Open gilius38 opened 9 years ago

gilius38 commented 9 years ago

According to jdbc spec: "Calling the method close on a Connection object that is already closed is a no-op." http://docs.oracle.com/javase/7/docs/api/java/sql/Connection.html#close()

This simple code throws an error:

    Class.forName("org.drizzle.jdbc.DrizzleDriver").newInstance();
    Connection conn = null;
    {
        conn = DriverManager.getConnection("jdbc:mysql:thin://" + HOST + ":"
                + PORT + "/" + DB, USER, PASS);
    }
    conn.close();
    conn.close();

Proposed fix in DrizzleConnection:

    public void close() throws SQLException {
        if (isClosed())
            return;
        ...

Note: I was unable to tell whether the timeoutExecutor could be running while protocol.isClosed() is true. It might be worth trying to this.timeoutExecutor.shutdown(); in any case