I am setting up a database with users and their passwords. I have a gui made in jfx 8, intellij IDE used
I have successfully extracted my code from my db and only when comparing them with if x == x i get the wrong password message
try {
Connection conn = DriverManager.getConnection("jdbc:sqlite:C:\\Users\\user\\Desktop\\java\\Java\\Just Messing Around\\MessyDB.db");
System.out.println("DB Connected");
Statement statement = conn.createStatement();
ResultSet rs = statement.executeQuery("SELECT * FROM UserDB WHERE Tab = " + tabelis);
while (rs.next()){
int id = rs.getInt("ID");
String name = rs.getString("Name");
int tab = rs.getInt("Tab");
String DBpassword = rs.getString("Password");
float right = rs.getFloat("Right");
System.out.println("********************");
System.out.println("********************");
System.out.println( "ID = " + id );
System.out.println( "Name = " + name );
System.out.println( "Tab = " + tab );
System.out.println( "Password = " + DBpassword );
System.out.println( "Right = " + right );
System.out.println();
String password1 = pfPassword.getText();
String password2 = DBpassword;
if (password1 == password2){
System.out.println("**************");
System.out.println("if statement ok");
Parent mainMenuParent = FXMLLoader.load(getClass().getResource("MainMenu.fxml"));
Scene mainMenuScene = new Scene(mainMenuParent);
Stage appStage = (Stage) ((Node) event.getSource()).getScene().getWindow();
appStage.setScene(mainMenuScene);
appStage.show();
statement.close();
conn.close();
}else{
System.out.println(pfPassword.getText() + " " + DBpassword);
System.out.println("wrong password");
statement.close();
conn.close();
}
In the sys out in else, after if statement it prints identical passwords
Else SysOut: lel lel wrong password