java - sql issue with parameter 6 -


hello guys i'm still new java programming.

i have problem no value specified parameter 6. i'm still searching problem. can guys me?

here's code

if (newdata == true) {          int p = joptionpane.showconfirmdialog(null, "do save?","insert",joptionpane.yes_no_option );     if(checkinputs() && imgpath != null && imgpath2 != null)     {         try {              connection con = getconnection();             preparedstatement ps = con.preparestatement("insert mmis(id,name,condi,image,image2,price,buyfrom,date)values(?,?,?,?,?,?,?,?)");              ps.setstring(1, txt_id.gettext());             ps.setstring(2, txt_name.gettext());             ps.setstring(3, txt_condi.gettext());              inputstream img = new fileinputstream(new file(imgpath));             ps.setblob(4, img);             inputstream img1 = new fileinputstream(new file(imgpath2));             ps.setblob(5, img1);             ps.executeupdate();              ps.setstring(6, txt_price.gettext());             ps.setstring(7, txt_buyfrom.gettext());             ps.setstring(8, txt_date.gettext());              show_mosquemanagementsystem_in_jtable();              joptionpane.showmessagedialog(null, "data inserted");         } catch (exception ex) {              joptionpane.showmessagedialog(null, ex.getmessage());       }                   }       else{         joptionpane.showmessagedialog(null, "one or more field empty");     } }                                           }          

you setting 5 parameters before calling ps.executeupdate. query expects 8 set. see question marks here

preparedstatement ps = con.preparestatement("insert mmis(id,name,condi,image,image2,price,buyfrom,date)values(?,?,?,?,?,?,?,?)"); 

you should call query after params set. in other words, change this:

        ps.setblob(5, img1);         ps.executeupdate();          ps.setstring(6, txt_price.gettext());         ps.setstring(7, txt_buyfrom.gettext());         ps.setstring(8, txt_date.gettext()); 

to this:

        ps.setblob(5, img1);         ps.setstring(6, txt_price.gettext());         ps.setstring(7, txt_buyfrom.gettext());         ps.setstring(8, txt_date.gettext());          ps.executeupdate(); 

Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -