我创建了一个jframe登录。它连接到sql。我遇到的问题是,如果我运行它并输入错误的凭证,else语句将执行3次。这是我的代码:
String username = txtUsername.getText();
String password = txtPassword.getText();
String sql = "select * from users where username ='"+username+"' and password='"+password+"'";
ResultSet res = st.executeQuery(sql);
for (int i=0; i<3;i++){
if (res.next()){
dispose();
up.show();
}
else{
txtUsername.setText("");
txtPassword.setText("");
JOptionPane.showMessageDialog(this, "Incorect inputs "+ i+ " attempts left");
}
}
暂无答案!
目前还没有任何答案,快来回答吧!