[英]Java Login 3 times Attempt Message box appears continuously
I am creating a login attempt that will block the user or exit the system if he put or typed a wrong user password. 我正在创建一个登录尝试,如果用户输入或输入错误的用户密码,它将阻止用户或退出系统。
Please help me why my message box keeps looping 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);
}
}
It seems that you don't break here on success: 看来您并没有因此而成功:
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.