java.sql.Statement.isClosed() throws an SQLException if the statement is closed - Mailing list pgsql-jdbc

From Christian Schlichtherle
Subject java.sql.Statement.isClosed() throws an SQLException if the statement is closed
Date
Msg-id 6E4A59F2-59FA-4751-B8D9-66832BE1FF84@schlichtherle.de
Whole thread Raw
Responses Re: java.sql.Statement.isClosed() throws an SQLException if the statement is closed  (Christian Schlichtherle <christian@schlichtherle.de>)
List pgsql-jdbc
Hi,

this bug applies to the JDBC driver version 9.3-1102-jdbc41. It only happens when using a PGPoolingDataSource. The bug
isin the proxy class for the Statement. Here’s some test code to provide evidence: 

<pre><code>
package cpssd.postgresql;

import org.junit.Test;
import org.postgresql.ds.PGPoolingDataSource;

import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Statement;

public class IsClosedIT {

    @Test(expected = SQLException.class)
    public void testIsClosed() throws SQLException {
        final PGPoolingDataSource ds = new PGPoolingDataSource();
        ds.setDatabaseName("postgres");
        try (Connection c = ds.getConnection()) {
            Statement s = c.createStatement();
            s.close();
            // Throws SQLException: Statement has been closed.
            assert s.isClosed();
        }
    }
}
</code></pre>

Regards,
Christian Schlichtherle

Attachment

pgsql-jdbc by date:

Previous
From: Craig Ringer
Date:
Subject: Re: [ODBC] BIRT report opening multiple connections
Next
From: Dave Cramer
Date:
Subject: Re: [ODBC] BIRT report opening multiple connections