"java.sql.SQLException: General error" even if the insert worked -
i'm doing program , if insert instructions work correctly , in db (microsoft access) ok, following code throws exception, doesn't @ all: insert presupuesto (id_cliente,id_presuspuesto,reserva) values (1,234, false) insert presupuesto (id_cliente,id_presuspuesto,reserva) values (1,234, false) java.sql.sqlexception: general error @ sun.jdbc.odbc.jdbcodbc.createsqlexception(unknown source) @ sun.jdbc.odbc.jdbcodbc.standarderror(unknown source) @ sun.jdbc.odbc.jdbcodbc.sqlexecdirect(unknown source) @ sun.jdbc.odbc.jdbcodbcstatement.execute(unknown source) @ sun.jdbc.odbc.jdbcodbcstatement.executeupdate(unknown source) @ datos.accesobd.insertapresupuesto(accesobd.java:137) @ aplicaciones.capaaplicacion.insertapresupuesto(capaaplicacion.java:81) @ interfaces.nuevopresupuesto$2.actionperformed(nuevopresupuesto.java:103) @ 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$200(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) hasta aqui bien insert productopresupuesto (id_producto,precioud,id_presuspuesto,unidades) values (1,123.0,234,1); hasta aqui bien insert productopresupuesto (id_producto,precioud,id_presuspuesto,unidades) values (2,270.0,234,1);
the printed statements executed, values printed in db. checked db , id there too.
productopresupuesto has 2 foreign keys primary keys , never repeated (i mean both @ same time).
here can see code:
public void insertapresupuesto(presupuesto presu){ string insert; for(int i=0; i<presu.getl().size(); i++){ insert="insert presupuesto (id_cliente,id_presuspuesto,reserva) values ("+presu.getc().getid_cliente()+","+presu.getid()+", "+presu.isreserva()+")"; statement stm1; try { stm1 = conn.createstatement(); system.out.printf("%s\n",insert); stm1.executeupdate(insert);//this line 137 } catch (sqlexception e) { // todo auto-generated catch block e.printstacktrace(); } } for(int i=0; i<presu.getl().size(); i++){ float precio=presu.getl().get(i).getprecioprod()-presu.getl().get(i).getrebaja(); system.out.printf("hasta aqui bien\n"); insert="insert productopresupuesto (id_producto,precioud,id_presuspuesto,unidades) values ("+presu.getl().get(i).getid()+","+precio+","+presu.getid()+","+presu.getunidades().get(i)+");"; statement stm2; try { stm2 = conn.createstatement(); system.out.printf("%s\n",insert); stm2.executeupdate(insert); } catch (sqlexception e) { // todo auto-generated catch block e.printstacktrace(); } } }
all items in "producto" exist, client exists too. function tries insert in presupuesto (which success without exception) , in productopresupuesto.
the existing tables cliente (with 1 example), producto (with loaded products, existing), presupuesto (which not throw exception) , table in between of last two: productopresupuesto (which succeeds insertions throws exception if object presupuesto (presu) has more 1 producto inside.
hope can give me idea, because i've been week, trying preparedstatements (same results).
thank you.
can highlight line 137 in accesobd.java.
datos.accesobd.insertapresupuesto(accesobd.java:137)
this narrow down problem coming from.
btw: i'll advise use preparedstatements. way you'll able set parameters dynamically , avoid string escaping errors. like:
preparedstatement ps = con.preparestatement("insert productopresupuesto (id_producto,precioud,id_presuspuesto,unidades) values (?,?,?)); ps.setstring(1, param1); ps.setstring(2, param2); ps.setstring(3, param3);
Comments
Post a Comment