From: | Christian Schlichtherle <christian(at)schlichtherle(dot)de> |
---|---|
To: | PostgreSQL mailing lists <pgsql-jdbc(at)postgresql(dot)org> |
Subject: | Statement.ececuteUpdate() closes ResultSet obtained from same Statement |
Date: | 2014-08-24 12:33:46 |
Message-ID: | C49EB260-863F-4173-A215-69E8FC0ED18E@schlichtherle.de |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-jdbc |
I am not sure if this is a bug or a feature, but here it goes:
package cpssd.postgresql;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import java.sql.*;
public class TicketIT {
private static Connection getConnection() throws SQLException {
return DriverManager.getConnection("jdbc:postgresql:postgres");
}
@Before
public void createTable() throws SQLException {
try (Connection c = getConnection();
Statement s = c.createStatement()) {
s.executeUpdate("CREATE TABLE test(a INT)");
}
}
@After
public void dropTable() throws SQLException {
try (Connection c = getConnection();
Statement s = c.createStatement()) {
s.executeUpdate("DROP TABLE test");
}
}
@Test(expected = SQLException.class)
public void testSharedStatementClosesResultSet() throws SQLException {
try (Connection c = getConnection();
Statement s = c.createStatement()) {
try (ResultSet rs = s.executeQuery("SELECT a FROM test")) {
s.executeUpdate("INSERT INTO test(a) VALUES (1)");
// Expected false, but throws SQLException: This statement has been closed.
assert !rs.next();
}
}
}
@Test
public void testUsingAnotherStatementWorks() throws SQLException {
try (Connection c = getConnection();
Statement s1 = c.createStatement()) {
try (ResultSet rs = s1.executeQuery("SELECT a FROM test")) {
try (Statement s2 = c.createStatement()) {
s2.executeUpdate("INSERT INTO test(a) VALUES (1)");
}
assert !rs.next();
}
}
}
}
From | Date | Subject | |
---|---|---|---|
Next Message | David G Johnston | 2014-08-24 14:11:57 | Re: Statement.ececuteUpdate() closes ResultSet obtained from same Statement |
Previous Message | Dave Cramer | 2014-08-21 14:08:59 | Re: Cursors removed with commit |