title: I'm trying to Validate username and password
body: <p>I am trying to ensure that when a user enters username &amp; password, authentication is done by checking if input matches some row in the user table. Here is the code so far: It doesn't respond when the login button is click. Please suggest how I can set it right. Thanks   </p>
  
  <pre><code> private void dbConnection()
  {
     try
     {
         Class.forName("com.mysql.jdbc.Driver");
         Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/maths_tutor", "root", "jesus");
         Statement stmt = conn.createStatement();
         String CHECK_USER = "SELECT * FROM records WHERE username = '"+this.txtUser+"' AND password = '"+this.txtPass+"'";
         ResultSet rs = stmt.executeQuery(CHECK_USER);
  
          while(rs.next())
          {
              String user = txtUser.getText();
              String pass = txtPass.getText();
  
              if(user.equals(rs.getString("username")))
              {
                  if(pass.equals(rs.getString("password")))
                  {
                      this.dispose();
                      new AboutTo().setVisible(true);
                  }
                  else JOptionPane.showMessageDialog(null, "Invalid Password");
              }
              else JOptionPane.showMessageDialog(null, "Invalid Username or Password");
          }
  
  
  
         stmt.close();
         rs.close();
         conn.close();
     }
  
  
     catch(SQLException | ClassNotFoundException er)
     {
         JOptionPane.showMessageDialog(null, "Exception:\n" + er.toString());
     }
  
  }
  </code></pre>