title: Exhausetd ResultSet Error when fetching from a perticular column
body: <p>In my project, I am creating a <strong>Cancel Account</strong> facility to delete the account from user table. The user table name is <code>newuser</code>. The <code>cancelaccount</code> jsp looks like:</p>
  
  <pre><code>&lt;%@ page language="java" contentType="text/html; charset=ISO-8859-1"
  pageEncoding="ISO-8859-1"%&gt;
  &lt;!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"&gt;
  &lt;html&gt;
   &lt;head&gt;
     &lt;style type="text/css"&gt;
  body {
  background-image: url("shocked.jpg");
  background-repeat:no-repeat;
  background-position: top right;
   }
  p
   {
      font-family: serif;
      font-weight: bold;
      color: blue;
      size: 5px;
      text-align: center;
   }
  
   &lt;/style&gt;
   &lt;meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"&gt;
   &lt;title&gt;Insert title here&lt;/title&gt;
   &lt;/head&gt;
   &lt;body&gt;
  
   &lt;form action="Cancelaccount" name="cancelaccount"&gt;
   &lt;p&gt;Are you sure to cancel account?&lt;/p&gt;
   &lt;p&gt;If yes please retype the password&lt;/p&gt;
   &lt;p&gt;&lt;input type="password" align="middle" name="password"&gt;&lt;/input&gt;&lt;/p&gt;
   &lt;input type="submit" value="Cancel Account"&gt;&lt;/input&gt;
   &lt;p&gt;Else click &lt;a href="UserHome.jsp"&gt;here&lt;/a&gt;&lt;/p&gt; 
   &lt;/form&gt;
   &lt;/body&gt;
   &lt;/html&gt;
  </code></pre>
  
  <p>In <code>Cancelaccount</code> servlet, I am trying to match the current input password with the password registered with the account open. If they match the account should be cancelled,otherwise not.So the servlet code is:</p>
  
  <pre><code>import getset.Getset;
  
  import java.io.IOException;
  import java.io.PrintWriter;
  
  import java.sql.SQLException;
  
  import accessdb.Dao;
  
  import javax.servlet.ServletException;
  import javax.servlet.http.HttpServlet;
  import javax.servlet.http.HttpServletRequest;
  import javax.servlet.http.HttpServletResponse;
  import javax.servlet.http.HttpSession;
  
  public class Cancelaccount extends HttpServlet {
      private static final long serialVersionUID = 1L;
  
      /**
       * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
       */
      protected void doGet(HttpServletRequest request,
                           HttpServletResponse response) throws ServletException,
                                                                IOException {
          // TODO Auto-generated method stub
          Getset g = new Getset();
          Dao dao = new Dao();
          PrintWriter pw = response.getWriter();
          String password = request.getParameter("password");
          HttpSession session = request.getSession();
          String userid = (String)session.getAttribute("userid");
          if (password.equals("") || password.equals(" "))
              response.sendRedirect("UserHome.jsp");
          g.setuserid(userid);
          g.setloginpassword(password);
          try {
              String password1 = dao.getregpasswordbyuserid(g);
              if (password1 == password) {
                  dao.cancelaccount(g);
                  pw.println("&lt;html&gt;Your Account has been successfully cancelled from the system.&lt;p&gt;" +
                             "Click here to go to &lt;a href=\"WelcomePage.jsp\"&gt;Start Page&lt;/a&gt;&lt;html&gt;");
                  session.invalidate();
  
              } else {
                  response.sendRedirect("UserHome.jsp");
              }
  
  
          } catch (ClassNotFoundException e) {
              e.printStackTrace();
          } catch (SQLException e) {
              e.printStackTrace();
          }
  
      }
  }
  </code></pre>
  
  <p>The <code>DAO</code> functions code are:</p>
  
  <pre><code>public void cancelaccount(Getset g)throws ClassNotFoundException,SQLException{
      //Delete a user from NEWUSER TABLE AND MEALDB TABLE
      Connection con=Dbconnection.getConnection();
      String userid=g.getuserid();
      PreparedStatement pstmt=con.prepareStatement("delete from mealdb where userid=?");
      pstmt.setString(1, userid);
      pstmt.executeUpdate();
      PreparedStatement pstmt1=con.prepareStatement("delete from newuser where userid=?");
      pstmt1.setString(1, userid);
      pstmt1.executeUpdate();
  }
  public String getregpasswordbyuserid(Getset g)throws ClassNotFoundException,SQLException{
      //GET PASSWORD BY USERID
      Connection con=Dbconnection.getConnection();
      String userid=g.getuserid();
      PreparedStatement pstmt=con.prepareStatement("select regpassword from newuser where userid=?");
      pstmt.setString(1, userid);
      ResultSet rs=pstmt.executeQuery();
      rs.next();
      String p=rs.getString(1);
      System.out.println(""+p);
      return p;
  
  }
  </code></pre>
  
  <p>And the <code>stacktrace</code> is:</p>
  
  <pre><code>    11:35:29,912 ERROR [STDERR] java.sql.SQLException: Exhausted Resultset
      11:35:29,912 ERROR [STDERR]     at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:125)
      11:35:29,912 ERROR [STDERR]     at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:162)
      11:35:29,912 ERROR [STDERR]     at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:227)
      11:35:29,912 ERROR [STDERR]     at oracle.jdbc.driver.OracleResultSetImpl.getString(OracleResultSetImpl.java:347)
      11:35:29,912 ERROR [STDERR]     at accessdb.Dao.getregpasswordbyuserid(Dao.java:245)
      11:35:29,912 ERROR [STDERR]     at Cancelaccount.doGet(Cancelaccount.java:39)
      11:35:29,912 ERROR [STDERR]     at javax.servlet.http.HttpServlet.service(HttpServlet.java:690)
      11:35:29,912 ERROR [STDERR]     at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
      11:35:29,912 ERROR [STDERR]     at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
      11:35:29,912 ERROR [STDERR]     at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
      11:35:29,912 ERROR [STDERR]     at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
      11:35:29,912 ERROR [STDERR]     at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
      11:35:29,912 ERROR [STDERR]     at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
       11:35:29,912 ERROR [STDERR]    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:230)
      11:35:29,912 ERROR [STDERR]     at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
      11:35:29,912 ERROR [STDERR]     at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:179)
      11:35:29,912 ERROR [STDERR]     at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:84)
      11:35:29,912 ERROR [STDERR]     at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
      11:35:29,912 ERROR [STDERR]     at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:104)
      11:35:29,912 ERROR [STDERR]     at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:157)
      11:35:29,912 ERROR [STDERR]     at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
      11:35:29,912 ERROR [STDERR]     at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:241)
      11:35:29,912 ERROR [STDERR]     at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
      11:35:29,912 ERROR [STDERR]     at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:580) 
      11:35:29,912 ERROR [STDERR]     at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
      11:35:29,912 ERROR [STDERR]     at java.lang.Thread.run(Unknown Source)
  </code></pre>
  
  <p>In the <code>DAO</code>s' <code>cancelaccount</code> function I deleted from another table <code>mealdb</code> also, because the <code>userid</code> field is a <code>primary key</code> in <code>newuser</code> and <code>foreign key</code> in <code>mealdb</code>. I looked into it hard, but could not find a way. Thank you.</p>