这是我用于删除功能的代码,但它似乎没有删除我选择的任何行。我首先使用jTextField searchTxt
搜索所需记录,然后删除匹配记录。匹配或搜索工作正常,其删除没有。
private void deleteSelectedRows(){
try{
if(searchCombo_User.getSelectedItem().toString().equals("User ID")){
dlt = "DELETE from user where user_id = ?";
}
else if(searchCombo_User.getSelectedItem().toString().equals("Username")){
dlt = "DELETE from user where username = ?";
}
pst = conn.prepareStatement(dlt);
pst.setString(1, searchTxt.getText());
((DefaultTableModel)userTable.getModel()).removeRow(userTable.getSelectedRow());
pst.execute();
}
catch (Exception e){
JOptionPane.showMessageDialog(null, e);
}
}
private void deleteBttnActionPerformed(java.awt.event.ActionEvent evt) {
if(!searchTxt.getText().isEmpty()){
deleteSelectedRows();
Update_table();
}
else{
JOptionPane.showMessageDialog(null, "Please search for the record you wish to delete");
}
}