【发布时间】:2019-01-25 12:47:30
【问题描述】:
我正在建立一个包含用户及其密码的数据库。我有一个用 jfx 8 制作的 gui,使用了 intellij IDE
我已经成功地从我的数据库中提取了我的代码,并且仅在将它们与 if x == x i get 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();
}
在 sys out in else 之后,在 if 语句之后打印相同的密码
其他系统输出: lel lel 密码错误
【问题讨论】:
-
试试
password1.equals(password2)。