Dan Rox Dan Rox - 1 month ago 4
Java Question

Java GUI syntax error in SQL statment

itemID STRING
purchesPrice DOUBLE
quantity DOUBLE
vendor STRING
unitM STRING

jcombo1=CB_vendor.getSelectedItem().toString();
jcombo2=CB_unit.getSelectedItem().toString();

conn=ShopDb.database();

Sql_insert="insert into table itemmanag(itemID,purchesPrice,sellPrice,quantity,vendor,unitM)
values
( "+txt_itemID.getText()+"','"+Item_Pprice.getText()+"','"+txt_itemSprice.getText()
+"','"+txt_qunti.getText()+"','" +jcombo1+"','"+jcombo2+ " ')";


ERROR:


you have an error in your sql syntax ; check the manual that corresponds to your MYSQL SERVER
version for the right syntanx to use near"table itemmanage(itemID,purchesPrice,quantity,vendor,
unitM)values(DA atline 1

JBA JBA
Answer

Oh my god, thanks @Orel Eraki, of course beside the unbalanced single-quotes you will have to follow proper SQL Insert Syntax and hava a form of 'INSERT INTO ...', try it like this (see my change dirctly after "values(" as the one of Orel Eraki (no 'table' "keyword" after into):

Sql_insert="insert into itemmanag(itemID,purchesPrice,sellPrice,quantity,vendor,unitM )values('"+txt_itemID.getText()+"','"+Item_Pprice.getText()+"','"+txt_itemSprice.getText()+"','"+txt_qunti.getText()+"','" +jcombo1+"','"+jcombo2+ "')";