sql - Java Inserting into database adds new data and it replaces the first row -
this code button, inserts data has been changed in text boxes of gui, once pressed.
i have been getting issue adds new row of data when press insert, replaces first row in table, end having first , last row equal in aspects.
may please me? appreciated.
private void jtogglebutton1actionperformed(java.awt.event.actionevent evt) { tblstudents stud = new tblstudents(); int row = jtable1.getrowcount(); row++; stud.setstudentid(row); stud.setfirstname(jtextfield2.gettext()); stud.setsurname(jtextfield3.gettext()); string birthd = dated.gettext(); simpledateformat sdf1 = new simpledateformat ("yyy-mm-dd"); try { date date = null; date = sdf1.parse(birthd); stud.setbirthdate(date); } catch (parseexception ex) {} stud.setgrade(jtextfield4.gettext()); stud.sethouseid (integer.parseint(jtextfield6.gettext())); studenthousepuentitymanager.gettransaction().begin(); studenthousepuentitymanager.persist(stud); studenthousepuentitymanager.gettransaction().commit(); tblstudentslist.clear(); tblstudentslist.addall(tblstudentsquery.getresultlist()); }
Comments
Post a Comment