java - Saving the Edited Data from Datatable in mysql -


i making jsf web page, show data of table, , edit, update, delete data database.

i using datatable, update method in loginbean class is

@managedbean(name = "loginbean" , eager=true) @viewscoped public class loginbean implements serializable {      private static final long serialversionuid = 1l;      private string emailid;     private string password;     boolean disabled = true;       @ejb     loginmanagerremote loginmanager;     entitymanager em;      list<login> list=null;       @postconstruct     public void init()     {system.out.println(">>>> in list  method <<<<");         list = new  arraylist<login>();         list = loginmanager.findall();     }      public list<login> getlist()     {         return list;     } public void setlist(list<login> list) {         this.list = list;     }       public string updateaction(login list) {       system.out.println(">>>> started in list loop <<<<");       loginmanager.update(list);        system.out.println(">>>> update nethod, ersisted data <<<<");       seteditable(false);           return "";  } 

the update method in login manager class is:

@override     public string update(login list){           // string query = "update employee set firstname = ?,lastname = ? id = 1";          try{            //query q = em.createquery("update login set uname = ?1,emailadd = ?2, pword= ?3 id = 1");          //   q.setparameter(1,this.uname);         //   q.setstring(2,this.emailadd);          //   q.setstring(3,this.pword);            list.getuname();            list.getpword();            list.getemailadd();              em.persist(list);            system.out.println(">>>>> m in login manager update method, , have persisted data <<");             return "users.xhtml";            }catch (exception e) {                system.out.println(">>>>> problem during update <<" + e.getmessage());                e.printstacktrace();                return null;            }          } 

this method gives error on id. duplicate entry key 1. in update method, how can tell update entries according id, , not update id.


Comments

Popular posts from this blog

matlab - "Contour not rendered for non-finite ZData" -

delphi - Indy UDP Read Contents of Adata -

javascript - Any ideas when Firefox is likely to implement lengthAdjust and textLength? -