Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to use Multiple resultsets with POSTGRES JDBC?
    primarykey
    data
    text
    <p>I am using JDBC on a PostgreSQL database. When I query for an entity in a resultset, it returns 5 rows. Related to that entity is another entity, for which I query while i am using a row in the above resultset. When I execute this query, the above resultset is closed.</p> <p>This means that it is allowing only 1 resultset to be active on 1 connection at a time.</p> <p>Previously the same code was working perfect for Oracle DB server.</p> <p>Is it that I need to ask the DB admin to configure the server to allow multiple resultsets? Or to do some change in the code? Or is it impossible to do it in postgre? Here is the code for more details:</p> <pre><code> Connection conn = PTSConnection.getConnection(); Statement stmt = conn.createStatement(); ResultSet lines = stmt.executeQuery("SELECT LINEID,STARTSTOPID,ENDSTOPID FROM LINES"); **//first resultset is active** while (lines.next()){ int lineId= lines.getInt(1); Stop ss = StopStorage.getByID(lines.getInt(2)); Stop es = StopStorage.getByID(lines.getInt(3)); ResultSet stops = stmt.executeQuery("SELECT STOPID FROM STOPSINLINES WHERE LINEID=" + lineId); **//first resultset dies** List&lt;Stop&gt; lineStops = new ArrayList&lt;Stop&gt;(); while(stops.next()){ Stop stop = StopStorage.getByID(stops.getInt(1)); lineStops.add(stop); } stops.close(); Line aLine = null; ResultSet emergencyLine = stmt.executeQuery("SELECT CAUSE, STARTTIME, ENDTIME FROM EMERGENCYLINES WHERE LINEID =" + lineId); if(emergencyLine.next()){ String cause = emergencyLine.getString(1); Time startTime = emergencyLine.getTime(2); Time endTime = emergencyLine.getTime(3); aLine = new EmergencyLine(ss, es, cause, startTime, endTime, (Stop[]) lineStops.toArray(new Stop[lineStops.size()])); } else { aLine = new Line(ss, es, (Stop[]) lineStops.toArray(new Stop[lineStops.size()])); } emergencyLine.close(); LineRepository.getInstance().addLine(aLine); } lines.close(); </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload