title: result set jsp - how to use?
body: <p>Can someone please tell me why this isn't working? I would like to be able to check if the username/password returned from the DB query is equal to a value. </p>
  
  <p>Session attribute "loginSuccess" always returns false, even if the values should be matching.</p>
  
  <pre><code>&lt;%@ page language="java" import="java.sql.*" %&gt;
  &lt;%
              String driver = "oracle.jdbc.driver.OracleDriver";
              Class.forName(driver).newInstance();
  
              Connection con = null;
              ResultSet rst = null;
              Statement stmt = null;
  
              try {
                  String url = "jdbc:oracle:thin:username/password@url:port:SID";
                  con = DriverManager.getConnection(url);
                  stmt = con.createStatement();
              } catch (Exception e) {
                  System.out.println(e.getMessage());
              }
              if (request.getParameter("action") != null) {
                  rst = stmt.executeQuery("select username, password"
                          + " from table");
                  }
  %&gt;
  
  
                  &lt;%
  
                  boolean loginCheck = false;
                             int count = 1;
                              while (rst.next()) {
  
  if(request.getParameter("action")!=null){
      if("username1"==rst.getString("username")){
          if("password1"==rst.getString("password")){
              loginCheck = true;
              }
          }
      }
  
                              count++;
                              }
  
                             if(loginCheck==true){
                                 session.setAttribute("loginSuccess", "true");
                                 }else{
                                 session.setAttribute("loginSuccess", "false");
                                 }
  
                              rst.close();
                              stmt.close();
                              con.close();
                  %&gt;
  
  &lt;jsp:forward page="login.jsp"/&gt;
  </code></pre>