db-derby-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Knut Anders Hatlen <Knut.Hat...@Sun.COM>
Subject Re: Can an embedded Derby connection support multiple simultaneous result sets?
Date Mon, 02 Feb 2009 16:10:52 GMT
"John T. Dow" <john@johntdow.com> writes:

> I think the answer is no, but I couldn't find anything in the documentation on the subject.
The best I found was this in one of the user group discussions...
>
>     The result set is closed as soon as one of the following occurs:
>     >   ...
>     >   another Statement object is executed on the same connection
>
> Is it necessary to open a new connection for each statement/resultset?

You can have multiple open statements per connection (but only one open
result set per statement). So this (untested) code which has two active
result sets at the same time on the same connection should work:

  Statement s1 = conn.createStatement();
  Statement s2 = conn.createStatement();

  ResultSet rs1 = s1.executeQuery("select * from t1");

  while (rs1.next()) {
    ResultSet rs2 = s2.executeQuery("select * from t2");
    while (rs2.next()) {
      //....
    }
  }

-- 
Knut Anders

Mime
View raw message