【发布时间】:2016-02-02 08:40:18
【问题描述】:
我使用的是 NetBeans 8.1。 我试图从我的 mysql 数据库中删除一条记录。记录已成功删除,但即使用户名和密码错误,我总是从我的 JOptionPane“已删除成功”中收到相同的消息。如果用户和密码正确,则删除记录成功。 如何在我的“执行更新”上设置条件,以便在详细信息与任何记录不匹配时收到不同的消息。 这是我的代码:
int a=JOptionPane.showConfirmDialog(rootPane, "Delete account?");
if(a==JOptionPane.YES_OPTION){
String passchk=enterpass.getText();
String userchk=enteruser.getText();
try{
Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/login_info", "root", "root");
Statement st=con.createStatement();
String sql="delete from users_info where"
+ " password='"+passchk+"'and username='"+userchk+"';";
st.executeUpdate(sql);
JOptionPane.showMessageDialog(null , "Deleted successfully");
}
catch(SQLException error){
JOptionPane.showMessageDialog(null, "error");
}
enterpass.setText("");
enteruser.setText("");
}
else {
setVisible(true);
cnfmdel.setVisible(false);
passconfirm.setVisible(false);
}
【问题讨论】: