pg.ddx.io pgsql-jdbc@postgresql.org mailing list archive
help / color / mirror / Atom feedStatement.ececuteUpdate() closes ResultSet obtained from same Statement
3+ messages / 3 participants
[nested] [flat]
* Statement.ececuteUpdate() closes ResultSet obtained from same Statement
@ 2014-08-24 12:33 Christian Schlichtherle <christian@schlichtherle.de>
2014-08-24 14:11 ` Re: Statement.ececuteUpdate() closes ResultSet obtained from same Statement David G Johnston <david.g.johnston@gmail.com>
2014-08-24 14:50 ` Re: Statement.ececuteUpdate() closes ResultSet obtained from same Statement Glenn Holmer <shadowm@lyonlabs.org>
0 siblings, 2 replies; 3+ messages in thread
From: Christian Schlichtherle @ 2014-08-24 12:33 UTC (permalink / raw)
To: 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();
}
}
}
}
Attachments:
signature.asc (application/pgp-signature, 494B) download
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: Statement.ececuteUpdate() closes ResultSet obtained from same Statement
2014-08-24 12:33 Statement.ececuteUpdate() closes ResultSet obtained from same Statement Christian Schlichtherle <christian@schlichtherle.de>
@ 2014-08-24 14:11 ` David G Johnston <david.g.johnston@gmail.com>
1 sibling, 0 replies; 3+ messages in thread
From: David G Johnston @ 2014-08-24 14:11 UTC (permalink / raw)
To: pgsql-jdbc
christian wrote
> I am not sure if this is a bug or a feature
Feature. Use one statement for each query you need active simultaneously.
David J.
--
View this message in context: http://postgresql.1045698.n5.nabble.com/Statement-ececuteUpdate-closes-ResultSet-obtained-from-same-...
Sent from the PostgreSQL - jdbc mailing list archive at Nabble.com.
--
Sent via pgsql-jdbc mailing list (pgsql-jdbc@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-jdbc
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: Statement.ececuteUpdate() closes ResultSet obtained from same Statement
2014-08-24 12:33 Statement.ececuteUpdate() closes ResultSet obtained from same Statement Christian Schlichtherle <christian@schlichtherle.de>
@ 2014-08-24 14:50 ` Glenn Holmer <shadowm@lyonlabs.org>
1 sibling, 0 replies; 3+ messages in thread
From: Glenn Holmer @ 2014-08-24 14:50 UTC (permalink / raw)
To: pgsql-jdbc
On 08/24/2014 07:33 AM, Christian Schlichtherle wrote:
> I am not sure if this is a bug or a feature, but here it goes:
> @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();
> }
> }
> }
http://docs.oracle.com/javase/7/docs/api/java/sql/Statement.html
"All execution methods in the Statement interface implicitly close a
statment's current ResultSet object if an open one exists."
--
Glenn Holmer (Linux registered user #16682)
"After the vintage season came the aftermath -- and Cenbe."
--
Sent via pgsql-jdbc mailing list (pgsql-jdbc@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-jdbc
^ permalink raw reply [nested|flat] 3+ messages in thread
end of thread, other threads:[~2014-08-24 14:50 UTC | newest]
Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2014-08-24 12:33 Statement.ececuteUpdate() closes ResultSet obtained from same Statement Christian Schlichtherle <christian@schlichtherle.de>
2014-08-24 14:11 ` David G Johnston <david.g.johnston@gmail.com>
2014-08-24 14:50 ` Glenn Holmer <shadowm@lyonlabs.org>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox