prepared statement - PreparedStatement Delete in Java -


i have written code delete record in mysql database java program. compiles , runs successfully, record still in datbase. suggestions?

jbutton btndelete = new jbutton("delete"); btndelete.addactionlistener(new actionlistener() {      public void actionperformed(actionevent arg0) {          try {              object[] options = {"yes", "no"};             component form = null;             int n = joptionpane.showoptiondialog(form, "do delete record student id: " +                     textfield_16.gettext() + " ?", "exit confirmation", joptionpane.yes_no_cancel_option, joptionpane.question_message, null, options, options);              if(n == joptionpane.yes_option) {                  string mock = textfield_16.gettext();                     string sql = "delete mockexam mockid =?";                 preparedstatement prest = con.preparestatement(sql);                 prest.setstring(1, mock);                 int val = prest.executeupdate();                 joptionpane.showmessagedialog(frmdeletemock, "the record has been deleted successfully.");             }         }          catch (sqlexception e) {             e.printstacktrace();             joptionpane.showmessagedialog(frmdeletemock, "record couldn't deleted. please try again.");         }            } });  btndelete.setbounds(45, 235, 89, 23); panel_1.add(btndelete); 

prest.setstring(1, "mockid"); 

you looking mockid equal mockid assume want delete entry id use:

string mockid = "2"; //set want set it. prest.setstring(1, mockid); int val = prest.executeupdate(); //check val happened. 

Comments

Popular posts from this blog

delphi - How to convert bitmaps to video? -

jasper reports - Fixed header in Excel using JasperReports -

python - ('The SQL contains 0 parameter markers, but 50 parameters were supplied', 'HY000') or TypeError: 'tuple' object is not callable -