java - Updating MySQL database by a JFrame form while refreshing the J table on the JFrame form -


enter image description here

i developed above form , update mysql database table 'employeeinfo'. form shows j table current data in database table 'employeeinfo'.

i coded select j table row , in relevant text fields in form.

but, i'm having trouble updating mysql database editing selected employees....**when edit text fields , hit update , database or jtable isn't updating **

database not updating , j table isn't refreshing..(may because of database table isn't updating)

update button actionperformed;

private void update_btnactionperformed(java.awt.event.actionevent evt) {                                                 try{         string val1 =txt_id.gettext();         string val2 =txt_name.gettext();         string val3 =txt_sname.gettext();         string val4 =((jtextfield)bday_chooser.getdateeditor().getuicomponent()).gettext();         string val5 =((jtextfield)wday_chooser.getdateeditor().getuicomponent()).gettext();          string sql = "update employeeinfo set employeeid='"+val1+"',name='"+val2+"',surname='"+val3+"', birthdate='"+val4+"',workstarteddate='"+val5+"' employeeid='"+val1+"' ";          pst=conn.preparestatement(sql);         pst.execute();          joptionpane.showmessagedialog(null, "user data updated...");      }catch(exception e){         joptionpane.showmessagedialog(null, e);     }     updatetable(); }                                           

updatetable method;

private void updatetable(){      try {         string sql = "select * employeeinfo";         pst=conn.preparestatement(sql);         rs=pst.executequery();         table_empinfo.setmodel(dbutils.resultsettotablemodel(rs));     } catch (exception ex) {         joptionpane.showmessagedialog(null, "error : "+ex);     }  } 

i changed coding follows;then worked; defined variable:string tableclick = (table_empinfo.getmodel().getvalueat(row,0).tostring());andstring sql = "update employeeinfo set employeeid='"+val1+"',name='"+val2+"',surname='"+val3+"', birthdate='"+val4+"',workstarteddate='"+val5+"' employeeid='"+tableclick+"' ";

string tableclick = (table_empinfo.getmodel().getvalueat(row,0).tostring()); 

added above variable , changed code follows;

string sql = "update employeeinfo set employeeid='"+val1+"',name='"+val2+"',surname='"+val3+"', birthdate='"+val4+"',workstarteddate='"+val5+"' employeeid='"+tableclick+"' "; 

Comments

Popular posts from this blog

How has firefox/gecko HTML+CSS rendering changed in version 38? -

android - CollapsingToolbarLayout: position the ExpandedText programmatically -

Listeners to visualise results of load test in JMeter -