簡體   English   中英

使用executeupdate從mysql數據庫(netbeans)中刪除記錄

[英]using executeupdate to delete record from mysql database(netbeans)

我正在使用 NetBeans 8.1。 我試圖從我的 mysql 數據庫中刪除一條記錄。 記錄已成功刪除,但即使用戶名和密碼錯誤,我也總是從我的 JOptionPane“成功刪除”中收到相同的消息。 如果用戶和密碼正確,則刪除記錄成功。 我如何在“executeupdate”上設置條件,以便在詳細信息與任何記錄不匹配時收到不同的消息。 這是我的代碼:

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);
    }

executeUpdate返回DELETE查詢的已刪除行數:

int deleted = st.executeUpdate(sql); 

if(deleted > 0)
 JOptionPane.showMessageDialog(null , "Deleted successfully");
else
 JOptionPane.showMessageDialog(null , "Nothing deleted");

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM