title: Error : java.sql.SQLException: Exhausted Resultset
body: <p>I am trying to give the online test, but this page is not opening when I click on the button to go to test page. 
  Here is part of that program :</p>
  
  <pre><code>try{
      int i=1;
      Random rand =new Random();
      int newrand=rand.nextInt(9);
      session.setAttribute("aptirandom",String.valueOf(newrand));
      Class.forName("oracle.jdbc.driver.OracleDriver");
      Connection con=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe","system","12345");
      String admitid=session.getAttribute("admitid").toString();
      int aid=Integer.parseInt(admitid); 
      PreparedStatement ps1=con.prepareStatement("select aptikey from result where admitid=?");
      ps1.setInt(1,aid);
      ResultSet rs1=ps1.executeQuery();
      rs1.next();
      if(rs1.getInt("aptikey")==1)
                     {
                      response.sendRedirect("AlreadyExam.jsp");
                      }
             else
             {
      PreparedStatement ps=con.prepareStatement("select * from aptitude where qid&gt;? order by qid");
      ps.setInt(1,newrand);
      ResultSet rs=ps.executeQuery();
          while(rs.next() &amp;&amp; i&lt;=10)
          {
      %&gt;
  
  
      &lt;form action="AptitudeResult.jsp" align="left" name="AptiForm"&gt;
  
  
          &lt;P&gt;&lt;b&gt;&lt;%=i%&gt;. &lt;%=rs.getString("question")%&gt;&lt;/b&gt;&lt;BR&gt;&lt;BR&gt;  
  &lt;input type="radio" name="answer&lt;%=i%&gt;" value="&lt;%=rs.getString("option1")%&gt;"&gt;&lt;font color="blue"&gt;&amp;nbsp;&amp;nbsp;A.&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;%=rs.getString("option1")%&gt;&amp;nbsp;
  </code></pre>
  
  <p>" value="&lt;%=rs.getString("option2")%>">&nbsp;&nbsp;B.&nbsp;&nbsp;&lt;%=rs.getString("option2")%><br><br>
  " value="&lt;%=rs.getString("option3")%>">&nbsp;&nbsp;C.&nbsp;&nbsp;&lt;%=rs.getString("option3")%>&nbsp;
  " value="&lt;%=rs.getString("option4")%>">&nbsp;&nbsp;C.&nbsp;&nbsp;&lt;%=rs.getString("option4")%><br><br>
              </p></p>
  
  <pre><code>             &lt;%
                  i++;
                       } rs.close();
                          ps.close();        
                          } 
                       con.close();
                       rs1.close();
                       ps1.close();
  
  
      }
      catch(NullPointerException e)
                            {
          response.sendRedirect("CandidateLogin.jsp");
      }
  
              %&gt;
  
  &lt;p&gt;&lt;input style="padding-top: 25px; font: 100% arial; border: 1px solid; width: 170px; margin: 0 0 0 212px; height: 33px; padding: 2px 0 3px 0;cursor: pointer;background: #7D0F0F; color: #FFF;"  class="submit" type="submit" name="TestButton" onclick="DoneTest()" value="Submit Aptitude Test"&gt;&lt;/p&gt;
  
  
                      &lt;/form&gt;
                      &lt;/div&gt;
                             &lt;/div&gt;
  
  
  
  
    &lt;div id="content_footer"&gt;&lt;/div&gt;
  
    &lt;div id="footer" &gt;
  Copyright © All Rigths Reserved  
    &lt;/div&gt;
  
    &lt;/div&gt;
              &lt;/body&gt;
                     &lt;/html&gt;
  
  Coding of aptituderesult.jsp is below : 
  </code></pre>
  
  <p>body></p>
  
  <pre><code>    &lt;div id="main"&gt;
  
      &lt;div id="header"&gt;
              &lt;div id="logo"&gt;
                   &lt;div id="logo_text"&gt;
  
        &lt;h1&gt;Online Recruitment System&lt;/h1&gt;
  
                  &lt;/div&gt;
              &lt;/div&gt;
      &lt;/div&gt;
  
  
  
  
    &lt;div id="site_content"&gt;
  
    &lt;div id="content"&gt;
  
   &lt;%
  
  try{
      String demo,answer,option;
  
   Connection con=null;
   String id;
   int aptimarks=0;
   int qid;
   int total=0;
   int i=1;
    String random=session.getAttribute("aptirandom").toString();
   try{
  
    Class.forName("oracle.jdbc.driver.OracleDriver");
    con=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe","system","12345");
             }
   catch(Exception e)
                       {
       e.printStackTrace();
     }
  
      PreparedStatement ps=con.prepareStatement("select * from aptitude where qid&gt;? order by qid");
      ps.setString(1,random); 
      ResultSet rs=ps.executeQuery();
      while(rs.next()){
          answer=rs.getString("answer");
          qid=rs.getInt("qid");
          id=String.valueOf(i);
          demo="answer".concat(id);
          option=request.getParameter(demo);
          if(answer.equals(option))
          {
              aptimarks++;
          }
          i++;
      }
  
  
      String admitid=session.getAttribute("admitid").toString();
      int aid=Integer.parseInt(admitid); 
  
  
      PreparedStatement ps1=con.prepareStatement("select total from result where admitid=?");
      ps1.setInt(1,aid);
      ResultSet rs1=ps1.executeQuery();
      rs1.next();
      total=rs1.getInt("total");
      total=total+aptimarks;
  
  
      PreparedStatement ps2=con.prepareStatement("update result set aptiresult=?,aptikey=1,total=? where admitid=?");
      ps2.setInt(1,aptimarks);
      ps2.setInt(2,total);
      ps2.setInt(3,aid);
      ps2.executeUpdate();
  
  
  
      response.sendRedirect("TestHome.jsp");
  
          }
  catch(NullPointerException e)
             {
      response.sendRedirect("TestHome.jsp");
  }
  </code></pre>
  
  <p>%></p>
  
  <pre><code>                &lt;/div&gt;
                             &lt;/div&gt;
  
  
  
  
    &lt;div id="content_footer"&gt;&lt;/div&gt;
  
    &lt;div id="footer" &gt;
    Copyright : Inderjeet Singh |Designed in JSP | JAVA | Struts |
    &lt;/div&gt;
  
    &lt;/div&gt;
              &lt;/body&gt;
                     &lt;/html&gt;
  </code></pre>