[Solved] JAVA – Passing values between Classes [duplicate]


Your Window_AfterLogin() constructor initializes another Window_Login which means there is the username, which you try to retrieve by window_login.getUserName()null.

In your after login code you could add another field username:

public Window_AfterLogin{
   private String username;

   public Window_AfterLogin(String username){
          initComponents();
          this.username = username;
   }
}

Where inside your LoginUser class you have to change the code accordingly:

    if(rs.next()) // Successful login
    {
        Window_AfterLogin window_afterlogin = new Window_AfterLogin(user);
        window_afterlogin.setVisible(true);
        this.dispose();
    }

Note:

Your application is vulnerable to SQL-Injections. Please read about prepared statements and how SQL-Injections work in theory and try to prevent them.

https://de.wikipedia.org/wiki/SQL-Injection
https://www.tutorialspoint.com/javaexamples/jdbc_prepared_statement.htm

solved JAVA – Passing values between Classes [duplicate]