Hi. I want to delete some specific data from my jtable.I made a table named student where i want to delete several data.Here remain 3 column stu_info,stu_name & Blood_group.To take input i used jtextfield and to delete i used delete button. I used the following code to delete.
private void cmd_deleteActionPerformed(java.awt.event.ActionEve nt evt) {
int p= JOptionPane.showConfirmDialog(null,"Do you really want to delete?","Delete",JOptionPane.YES_NO_OPTION);
if(p==0){
String sql="Delete from student where stu_id=? AND stu_name=? AND Blood_group=?";
try{
pst=conn.prepareStatement(sql);
pst.setString(1, jTextField1.getText());
pst.setString(2, jTextField2.getText());
pst.setString(3, jTextField3.getText());
pst.execute();
}
catch(Exception e){
JOptionPane.showMessageDialog(null, e);
}
Update_table();
}
}
But here to delete a row i have to i have to put all 3 value of my 3 column as input. Sometimes i wanna delete some rows which contain a specific value of a column.(for example i want to delete all row contain Blood_group=O+) . Sometime i want to delete the rows which caontain a specific value of a column & another specific value of another column.(for example delete all row containing Blood_group=B+ and stu_name=mark). How can i do that? Please help.Here is the jframe view of my program.
Capture.jpg