[英]Java Login 3 times Attempt Message box appears continuously
我正在創建一個登錄嘗試,如果用戶輸入或輸入錯誤的用戶密碼,它將阻止用戶或退出系統。
請幫我為什么我的消息框會不斷循環播放?
private void login() {
String stru = "";
stru = TxtUserName.getText();
String strp = "";
strp = TxtPassword.getText();
if (stru.isEmpty() == true) {
JOptionPane.showMessageDialog(null, "Enter User Name");
return;
}
if (strp.isEmpty() == true) {
JOptionPane.showMessageDialog(null, "Enter Password");
return;
}
try {
//get database connection details
Connect mc = new Connect();
//open connection
Connection connection;
connection = DriverManager.getConnection(mc.StrUrl, mc.StrUid, mc.StrPwd);
String str = "";
str = "select * from lib_user where user_name =? and user_password =?";
PreparedStatement pst = connection.prepareStatement(str);
pst.setString(1, stru);
pst.setString(2, strp);
ResultSet rs;
rs = pst.executeQuery();
int i = 0;
do {
if (rs.next()) {
Connect.StrUser = TxtUserName.getText();
MainForm m = new MainForm();
this.setVisible(false);
JOptionPane.showMessageDialog(null, "Welcome to BIR Library Management System", "Welcome", JOptionPane.INFORMATION_MESSAGE);
m.setVisible(true);
} else {
i++;
// TxtPassword.disable();
// TxtUserName.disable();
JOptionPane.showMessageDialog(null, "User name or password are not correct." + i);
// return;
}
} while (i < 3);
System.out.println("You screwed up.");
} catch (Exception e) {
{
JOptionPane.showMessageDialog(null, e, "Error", JOptionPane.ERROR_MESSAGE);
}
// System.exit(1);
}
}
看來您並沒有因此而成功:
if (rs.next()) {
Connect.StrUser = TxtUserName.getText();
MainForm m = new MainForm();
this.setVisible(false);
JOptionPane.showMessageDialog(null, "Welcome to BIR Library Management System", "Welcome", JOptionPane.INFORMATION_MESSAGE);
m.setVisible(true);
// no break here...
} else {
i++;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.