Updated in a database [update ... set] java -
i have problem java code. when database update don't work . used 3 methods found on internet , still have not worked! me thank in advance
package hlr_serveur; public class model_hlr{ public void setupdate(string[] information) { int imsdn_values,cins,kcs,kis; long imsi_values=0; this.imsi_values = long.parselong(information[0]); this.imsdn_values = integer.parseint(information[1]); this.kis = integer.parseint(information[2]); this.kcs = integer.parseint(information[3]); this.service = new string(information[4]); this.nom = new string(information[5]); this.prenom = new string(information[6]); this.cins = integer.parseint(information[7]); system.out.println(this.imsi_values); system.out.println(this.imsdn_values); system.out.println(this.kis); system.out.println(this.kcs); system.out.println(this.service); system.out.println(this.nom); system.out.println(this.prenom); system.out.println(this.cins); try { class.forname("com.mysql.jdbc.driver"); dbconnect = drivermanager.getconnection("jdbc:mysql://localhost/abonnes", "root",""); dbstatement = dbconnect.createstatement(); /* test 1: preparedstatement preparestatement = (preparedstatement) dbconnect.preparestatement("update sim set ismidn="+this.imsdn_values +", ki="+this.kis +",kc="+this.kcs+",service='"+this.service +"',nom='"+this.nom +"',prenom='"+this.prenom +"',cin="+this.cins +" imsi="+this.imsi_value+""); k=preparestatement.executeupdate(); test 2: preparedstatement checkdb = (preparedstatement) dbconnect.preparestatement( "update sim set ismidn= ? ,ki= ?,kc= ?,service= ?,nom= ?,prenom= ?,cin= ? ismi= ? "); checkdb.setint(1,this.imsdn_values); checkdb.setint(2,this.kis); checkdb.setint(3,this.kcs); checkdb.setstring(4,this.service); checkdb.setstring(5,this.nom); checkdb.setstring(6,this.prenom); checkdb.setint(7,this.cins); checkdb.setlong(8,this.imsi_values); k=checkdb.executeupdate(); */ /* test 3: */ dbstatement=dbconnect.createstatement(resultset.type_scroll_sensitive,resultset.concur_updatable); resultset uprs = dbstatement .executequery("select * sim ismi ='" + this.imsi_values + "'"); uprs.movetoinsertrow(); uprs.updateint("ismidn", this.imsdn_values); uprs.updateint("ki", this.kis); uprs.updateint("kc", this.kcs); uprs.updatestring("service", this.service); uprs.updatestring("nom", this.nom); uprs.updatestring("prenom", this.prenom); uprs.updateint("cin", this.cins); uprs.insertrow(); uprs.beforefirst(); dbstatement.close(); dbconnect.close(); } catch (sqlexception ex) { logger.getlogger(view.class.getname()).log(level.severe, null, ex); } catch (classnotfoundexception ex) { logger.getlogger(view.class.getname()).log(level.severe, null, ex); } }
mai 12, 2015 12:20:55 hlr_serveur.model_hlr setupdate grave: null com.mysql.jdbc.exceptions.mysqlintegrityconstraintviolationexception: column 'ismi' cannot null @ com.mysql.jdbc.sqlerror.createsqlexception(sqlerror.java:931) @ com.mysql.jdbc.mysqlio.checkerrorpacket(mysqlio.java:2941) @ com.mysql.jdbc.mysqlio.sendcommand(mysqlio.java:1623) @ com.mysql.jdbc.mysqlio.sqlquerydirect(mysqlio.java:1715) @ com.mysql.jdbc.connection.execsql(connection.java:3249) @ com.mysql.jdbc.preparedstatement.executeinternal(preparedstatement.java:1268) @ com.mysql.jdbc.preparedstatement.executeupdate(preparedstatement.java:1541) @ com.mysql.jdbc.preparedstatement.executeupdate(preparedstatement.java:1455) @ com.mysql.jdbc.preparedstatement.executeupdate(preparedstatement.java:1440) @ com.mysql.jdbc.updatableresultset.insertrow(updatableresultset.java:739) @ hlr_serveur.model_hlr.setupdate(model_hlr.java:304) @ hlr_serveur.abonnepanel_rechercher.actionperformed(abonnepanel_rechercher.java:401) @ javax.swing.abstractbutton.fireactionperformed(unknown source) @ javax.swing.abstractbutton$handler.actionperformed(unknown source) @ javax.swing.defaultbuttonmodel.fireactionperformed(unknown source) @ javax.swing.defaultbuttonmodel.setpressed(unknown source) @ javax.swing.plaf.basic.basicbuttonlistener.mousereleased(unknown source) @ java.awt.component.processmouseevent(unknown source) @ javax.swing.jcomponent.processmouseevent(unknown source) @ java.awt.component.processevent(unknown source) @ java.awt.container.processevent(unknown source) @ java.awt.component.dispatcheventimpl(unknown source) @ java.awt.container.dispatcheventimpl(unknown source) @ java.awt.component.dispatchevent(unknown source) @ java.awt.lightweightdispatcher.retargetmouseevent(unknown source) @ java.awt.lightweightdispatcher.processmouseevent(unknown source) @ java.awt.lightweightdispatcher.dispatchevent(unknown source) @ java.awt.container.dispatcheventimpl(unknown source) @ java.awt.window.dispatcheventimpl(unknown source) @ java.awt.component.dispatchevent(unknown source) @ java.awt.eventqueue.dispatcheventimpl(unknown source) @ java.awt.eventqueue.access$500(unknown source) @ java.awt.eventqueue$3.run(unknown source) @ java.awt.eventqueue$3.run(unknown source) @ java.security.accesscontroller.doprivileged(native method) @ java.security.protectiondomain$1.dointersectionprivilege(unknown source) @ java.security.protectiondomain$1.dointersectionprivilege(unknown source) @ java.awt.eventqueue$4.run(unknown source) @ java.awt.eventqueue$4.run(unknown source) @ java.security.accesscontroller.doprivileged(native method) @ java.security.protectiondomain$1.dointersectionprivilege(unknown source) @ java.awt.eventqueue.dispatchevent(unknown source) @ java.awt.eventdispatchthread.pumponeeventforfilters(unknown source) @ java.awt.eventdispatchthread.pumpeventsforfilter(unknown source) @ java.awt.eventdispatchthread.pumpeventsforhierarchy(unknown source) @ java.awt.eventdispatchthread.pumpevents(unknown source) @ java.awt.eventdispatchthread.pumpevents(unknown source) @ java.awt.eventdispatchthread.run(unknown source)
problems mai 12, 2015 1:42:15 hlr_serveur.model_hlr setupdate grave: null com.mysql.jdbc.exceptions.mysqlintegrityconstraintviolationexception: duplicate entry '216011100258963' key 'primary
from log posted answer, column ismi mandatory field database table, seems primary key.
you need like:
uprs.updateint("ismi", somevalue);
to complete new row data.
please note primary key must unique in table.
Comments
Post a Comment