title: java.sql.SQLException: Result set after last row
body: <p>I think I am having problem because of this line <code>rs.next();</code> in the <code>RequestDaoImpl</code> class mentioned below. Whenever I try to retrieve the value of <code>STATUS</code>, I keep on getting the following error:</p>
  
  <p><code>java.sql.SQLException: Result set after last row</code></p>
  
  <p>What am I doing wrong here?</p>
  
  <pre><code>  @Component
      public class GetStatus {
  
          @JmsListener(destination = "Queue1")
          public void processStatusMessage(String message) throws DaoException {
  
              System.out.println("Message Retrieved is:" +message);
  
              try {
  
              RequestDao requestDao = (RequestDao) context.getBean("requestDao");
  
              String receivedStatus = requestDao.getRequestStatus(message);
  
              System.out.println("Testing March 11");
              System.out.println(receivedStatus);
  
  
  
              }
              catch(Throwable th){
                  th.printStackTrace();   
  
              }
  
           }
  
          private static ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("ApplicationContext.xml");
  
  
  
      }
  </code></pre>
  
  <p>My RequestDao is : </p>
  
  <pre><code>public interface RequestDao {
  
      public String getRequestStatus(String msg)throws DaoException;
  
  }
  </code></pre>
  
  <p>My RequestDaoImpl with the method implementation: </p>
  
  <pre><code>public class RequestDaoImpl implements RequestDao {
  
      public void setDataSource(DataSource dataSource) 
      {       
          jdbcTemplate = new JdbcTemplate(dataSource);                                    
      }
  
      @Override
      public String getRequestStatus(String msg) throws DaoException {
          DataSource ds = null;
          Connection conn = null;
          PreparedStatement pstmt = null;
          ResultSet rs = null;
          String requestStatus = null;
  
          //List&lt;String&gt; mylist = new ArrayList&lt;String&gt;();
  
           try {
  
                  ds = jdbcTemplate.getDataSource();
                  conn = ds.getConnection();  
  
                  //I am receiving message like this hence splitting it : 123456#Tan#development
                   String[] parts =   msg.split("#");
                   String requestID = parts[0].trim();
                   String userName =  parts[1].trim();
                   String applicationName = parts[2].trim();
  
  
                  /*===========================================================================*/
                  /*    Code to get the request status from Mytable          */ 
                  /*===========================================================================*/
                  pstmt = conn.prepareStatement("SELECT STATUS FROM Mytable WHERE request_user= ? and app_name =? and request_id=?");
                  pstmt.setString(1,userName);
                  pstmt.setString(2,applicationName);
                  pstmt.setString(3, requestID);
                  rs = pstmt.executeQuery();  
                  rs.next();
                  System.out.println("The status received is as follows:");
  
                  requestStatus = rs.getString("STATUS");
                  System.out.println(requestStatus);
  
  
  
          }
           catch(Throwable th) {
                  throw new DaoException(th.getMessage(), th);
              }
              finally {
                  if (rs != null) { try { rs.close(); } catch (SQLException e) { e.printStackTrace(); }}
                  if (pstmt != null) { try { pstmt.close(); } catch(SQLException sqe) { sqe.printStackTrace(); }}
                  if (conn != null) { try { conn.close(); } catch (SQLException sqle) { sqle.printStackTrace(); }}
  
              }   
  
  
  
          return requestStatus;
      }
    private JdbcTemplate jdbcTemplate;    
   }
  </code></pre>
  
  <p>Saw similar error post <a href="https://stackoverflow.com/questions/26418840/java-sql-resultset-exception">here</a> but their code is different than mine.</p>