java - Update Data in a MySQL Database -
i want update data, weight (2.150kg
), in mysql database.
this code used in netbeans:
connectdb(); try{ string value1 = txt_search_code.gettext(); string value2 = txt_item_code.gettext(); string value3 = txt_discription.gettext(); string value4 = txt_bin_balance.gettext(); string value5 = txt_date.gettext(); string value6 = txt_issued_quantaty.gettext(); string value7 = txt_issued_inno.gettext(); string value8 = txt_arrived_quantaty.gettext(); string value9 = txt_arrived_inno.gettext(); string value10 = txt_final_bin_balance.gettext(); string sql = "update tbl_codes set no='"+value1+"',item_code='"+value2+"',discription='"+value3+"',previous_bin_balance='"+value4+ "',date='"+value5+"',issued_quantaty='"+value6+"',issued_invoice_no='"+value7+"',arrived_quantaty='"+value8+"',arrived_invoice_no='"+value9+"',final_bincard_balance='"+value10+"'where no='"+value1+"' "; preparedstatement pstmt = con.preparestatement(sql); pstmt.execute(); joptionpane.showmessagedialog(null, " new records updated succsessfully!!"); }catch(exception e){ joptionpane.showmessagedialog(null,e); } closedb();
this sql update statement:
select `tbl_stock`.`no`, `tbl_stock`.`item_code`, `tbl_stock`.`discription`, `tbl_stock`.`previous_bin_balance`, `tbl_stock`.`date`, `tbl_stock`.`issued_quantaty`, `tbl_stock`.`issued_invoice_no`, `tbl_stock`.`arrived_quantaty`, `tbl_stock`.`arrived_invoice_no`, `tbl_stock`.`final_bincard_balance` `db_biling`.`tbl_stock`;
how can update weight?
try use executeupdate()
instead of execute()
. code need refine lot. check sample code
string sql = "update tbl_codes set no= ?,item_code=?,discription=?,previous_bin_balance=? ,date=?,issued_quantaty=?,issued_invoice_no=?,arrived_quantaty=?,arrived_invoice_no=?,final_bincard_balance=? no=?"; preparedstatement pstmt = con.preparestatement(sql); pstmt.setstring(1, value1); pstmt.setstring(2, value2); pstmt.setstring(3, value3); pstmt.setstring(4, value4); pstmt.setstring(5, value5); pstmt.setstring(6, value6); pstmt.setstring(7, value7); pstmt.setstring(8, value8); pstmt.setstring(9, value9); pstmt.setstring(10, value10); pstmt.setstring(11, value1); pstmt.executeupdate();
if use preparedstatement
, use ?
instead of concatenating values sql, '"+value1+"'
. using ?
more clear , more secure.
Comments
Post a Comment