title: What does "if (rs.next())" mean?
body: <p>I am currently getting the error,</p>
  
  <pre><code>java.sql.SQLException: Method 'executeQuery(String)' not allowed on prepared statement.
  </code></pre>
  
  <p>because I am using</p>
  
  <pre><code>PreparedStatement stmt = conn.prepareStatement(sql);
  </code></pre>
  
  <p>and also had</p>
  
  <pre><code>ResultSet rs = stmt.executeQuery(sql);
  </code></pre>
  
  <p>in my code.</p>
  
  <p>I now need to remove the ResultSet line but that leaves me with having to deal with the following code:</p>
  
  <pre><code>if (rs.next()) {
      messages.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("login.successful"));
      request.getSession(true).setAttribute("USERNAME", rs.getString("USERNAME"));
      request.getSession(true).setAttribute("BALANCE", rs.getString("BALANCE"));
      request.setAttribute("msg", "Logged in successfully");
  </code></pre>
  
  <p>I'm not sure I completely understand what</p>
  
  <pre><code> if (rs.next())
  </code></pre>
  
  <p>does.  Could someone explain this code to me?  If I have a better understanding of that I believe I'll have a better idea on how to deal using the PreparedStatement results with the logic being used for rs.  Also any help to deal with changing that logic would be greatly appreciated too.</p>