将数据从JComboBox存储在后端(表)中

时间:2018-09-30 11:02:02

标签: sql swing exception

这里的语法错误是什么?

What is the syntax error here?

我收到此语法错误。我想从 Jcombobox 将数据存储在数据库中。 FoodnameQty是我的表格列名称。

String Foodname=starter.getSelectedItem().toString();
String Qty=starterqty.getText();
    try{
           pst=con.prepareStatement("insert into order values(?,?)");
           pst.setString(1,Foodname);
           pst.setString(2,Qty);
           pst.execute();

        JOptionPane.showMessageDialog(null, "Data is saved");

    }
    catch(Exception ex)
    {
        JOptionPane.showMessageDialog(null,ex); 
    }

2 个答案:

答案 0 :(得分:1)

您有一个名为await的表,在order数据库中MySQL/MariaDB是保留字,您应该更改表名或使用如下引号,

order

或者只是更改表名,

insert into `order` values(?,?)

希望这会有所帮助。

答案 1 :(得分:0)

错误提示您查询无效