hello, i have this question. i want to update a data base record. so i am using this coding. PreparedStatement st_stockaddps=st_stockaddcon.prepareStatement("INSERT INTO inventory VALUES("+st_descriptionst+","+st_ppust+","+st_qtyst+","+st_reorderlevelst+","+st_suppliercodest+","+st_totalcostst+","+st_totalcostst+")WHERE I_Code=?"); st_stockaddps.setString(1,st_itemcodest); st_stockaddps.executeUpdate(); but the problem is when i execute this statement it gives a sql exception saying "Missing semicolon( at the end of sql statement.. please send a quick reply. thank you.
SCJP 1.4, SCMAD 1.0<br />SCWCD, SCBCD (in progress)
try { PreparedStatement pst=con.prepareStatement("Insert Into SavingAccountRecord(ACCOUNTNUMBER,BRANCHCODE,ACCOUNTTYPE,OPENDATE) Values(?,?,?,?)"); pst.setString(1,ACCOUNTNUMBER); pst.setString(2,BRANCHCODE); pst.setString(3,ACCOUNTTYPE); pst.setString(4,OPENDATE); pst.executeUpdate(); pst.close(); System.out.println(" registered"); }catch(Exception e) { try{con.close();}catch(Exception e2){System.out.println("connection not closed");} System.out.println("could not register"); }
Andy Bowes
Ranch Hand
Joined: Jan 14, 2003
Posts: 171
posted
0
If you are trying to Update an existing record rather than create a new record the SQL statement that you are after should look something like : PreparedStatement st_stockaddps=st_stockaddcon.prepareStatement("UPDATE inventory SET description = ?, unitprice = ?, quantity = ?, reorderlevel = ?, suppliercode = ?, totalcost = ? WHERE I_Code = ?"); st_stockaddps.setString(1,st_descriptionst); st_stockaddps.setString(2,st_ppust); st_stockaddps.setString(3,st_qtyst); st_stockaddps.setString(4,st_reorderlevelst); st_stockaddps.setString(5,st_suppliercodest); st_stockaddps.setString(6,st_totalcostst); st_stockaddps.setString(7,st_itemcodest); st_stockaddps.executeUpdate(); [ April 16, 2003: Message edited by: Andy Bowes ]
Andy Bowes<br />SCJP, SCWCD<br />I like deadlines, I love the whoosing noise they make as they go flying past - Douglas Adams