我想从 mySql 数据库登录。一切都很好,但是当我登录时,我的错误消息出现了 2 次(用户名或密码不匹配。)。我认为我的循环有问题。请帮我。我的方法如下......
private void loginProcess() {
String username = jTextFieldLoginUsername.getText().toUpperCase();
String password = jPasswordFieldLoginPassword.getText();
List<LoginModel> list = new ArrayList<LoginModel>();
LoginDao loginDao = new LoginDao();
list = loginDao.doLogin();
if (list.size() != 0) {
for (LoginModel model : list) {
String uName = model.getUsername();
String pWord = model.getPassword();
String userType = model.getUserType();
// System.out.println("uName::" + uName);
if (username.equals(uName) && password.equals(pWord)) {
if (userType.equals("1")) {
dispose();
Admin admin = new Admin();
admin.setVisible(true);
} else if (userType.equals("2")) {
dispose();
Purchase purchase = new Purchase();
purchase.setVisible(true);
} else if (userType.equals("3")) {
dispose();
Sales sales = new Sales();
sales.setVisible(true);
}
} else {
JOptionPane.showMessageDialog(rootPane, "Username or Password does not match.");
jTextFieldLoginUsername.requestFocus();
jTextFieldLoginUsername.selectAll();
}
}
} else {
}
}