title: Object reference returns null Java
body: <p>I'm running a simple Java login system, using MySQL.</p>
  
  <p>The login works fine, but I want to create an object of the user that has been logged in via get methods. But when outputting these methods they return null:</p>
  
  <p>"Logged in with null and null".</p>
  
  <p>What am I doing wrong?</p>
  
  <p>-- MAIN --</p>
  
  <pre><code>public class Main {
  
  
  public static void main(String[] args) {
  
      Scanner input = new Scanner(System.in);
      User u = new User();
  
      String username;
      String password;
  
      System.out.println("Enter Username: ");
      username = input.next();
  
      System.out.println("Enter Password: ");
      password = input.next();
  
      DatabaseController dc = new DatabaseController();
      dc.login(username, password);
  
      if(dc.a){
          System.out.print("Logged in with "+ u.getUsername()+ " and " +u.getPassword());
      }
      else{
          System.out.println("mismatch");
      }
  
  }
  
  }
  </code></pre>
  
  <p>-- DATABASE CONTROLLER ---</p>
  
  <pre><code>public class DatabaseController {
  
  private DatabaseConnection db;
  ResultSet rs;
  boolean a;
  User u = null;
  
  String name;
  String pass;
  
  public DatabaseController()
  {
      db = new DatabaseConnection();
  }
  
  public boolean login(String username, String password)
  {
  
      try
      {
          rs = db.doQuery("SELECT Firstname, Password FROM Users WHERE Firstname ='"+ username+"';");
          while(rs.next())
          {
              name = rs.getString(1);
              pass = rs.getString(2);
              if(pass.equals(password)){
                  a = true;
                  u = new User();
                  u.setPassword(password);
                  u.setUsername(username);
              }
          }
      }
      catch(Exception ex)
      {
          ex.printStackTrace();
      }
      return a;
  }
   }
  </code></pre>
  
  <p>--- USER ---</p>
  
  <pre><code>public class User {
  
  private String username;
  private String password;
  
  public String getUsername() {
      return username;
  }
  public void setUsername(String username) {
      this.username = username;
  }
  public String getPassword() {
      return password;
  }
  public void setPassword(String password) {
      this.password = password;
  }
  
  }
  </code></pre>