title: Java JDBC Single Statement object before while loop and inside while loop
body: <p>I am writing one core java program with JDBC to connect to Oracle. </p>
  
  <ul>
  <li>I am selecting my First table with a select condition to get few row ids. I got some records selected in the resultset</li>
  <li>Now I am looping the resultset in a while loop (while resultSet.next())</li>
  <li>Then selecting my second table for the rows whose ids are equal to the ids in the 1st resultset</li>
  </ul>
  
  <p>In both selects I am using the same Statement object. While running the program I am getting only 1st row details and then java is throwing the error that resultset is closed</p>
  
  <p>In short, I wanted to know whether I can use one single Statement object before the loop and inside the loop ?</p>
  
  <p>Below is my code sample</p>
  
  <pre><code>allCOBbatchRSet=stmt.executeQuery("SELECT RECID FROM V_F_BATCH WHERE BATCH_STAGE IS NOT NULL");
  while (allCOBbatchRSet.next())
  {
          BatchRSet=stmt.executeQuery("SELECT XMLRECORD FROM F_BATCH WHERE RECID="+cobBatchRecId);
          BatchRSet.next();
          ............
  }
  </code></pre>
  
  <p>It failed with the exception</p>
  
  <pre><code>java.sql.SQLException: Closed Resultset: next at
  oracle.jdbc.driver.InsensitiveScrollableResultSet.ensureOpen(InsensitiveScrollableResultSet.java:109) at
  oracle.jdbc.driver.InsensitiveScrollableResultSet.next(InsensitiveScrollableResultSet.java:398) at
  com.manohar.t24.COBDetails.getCOBDetails(COBDetails.java:46) 
  </code></pre>