Обсуждение: Statement.ececuteUpdate() closes ResultSet obtained from same Statement

Поиск
Список
Период
Сортировка

Statement.ececuteUpdate() closes ResultSet obtained from same Statement

От
Christian Schlichtherle
Дата:


Вложения

Re: Statement.ececuteUpdate() closes ResultSet obtained from same Statement

От
David G Johnston
Дата:
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-Statement-tp5816031p5816032.html
Sent from the PostgreSQL - jdbc mailing list archive at Nabble.com.


Re: Statement.ececuteUpdate() closes ResultSet obtained from same Statement

От
Glenn Holmer
Дата:
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."