title: Java username and password validation with Database
body: <p>I am trying to validate user input with database information.  So if a user enters a username it will check to see if there is a match with the database.</p>
  
  <pre><code>public void login() throws SQLException {
          boolean loginUsername = false;
          boolean loginPassword = false;
          String input = null;
  
          while(input == null) {
              System.out.println(message.loginUsername());
              input = in.nextLine();
  
              try {
                  preparedStatement = connect.prepareStatement("SELECT username FROM doom.accounts;");
                  rs = preparedStatement.executeQuery();
  
                  while(rs.next()) {
                      String username = rs.getString("username");
  
                      if(!input.equals(username)) {
                          System.out.println(message.invalidUsername());
                          input = null;
                      } else {
                          loginUsername = true;
                      }
                  }
              } catch(SQLException e) {
  
              } finally {
                  if(statement != null) {
                      statement.close();
                  }
              }
          }
  }
  </code></pre>
  
  <p>I posted just the username part of the method.  I have debugged and can confirm that my user input does equal a valid username from the database but I am still getting invalid username message when it shouldnt.</p>