UPDATE表的语法错误

时间:2017-05-27 18:09:05

标签: java mysql

自从我使用UPDATE TABLE语句2小时后,我总是出现语法错误。我做了这个:

String falseValue = "False";
String emptyValue = "";
try {
        OrderListViewerModel orderlistviewermodell = (OrderListViewerModel) tableOrder.getSelectionModel().getSelectedItem();
        pst = conn.prepareStatement("UPDATE TABLE productList SET ordered = '" + falseValue + "', orderedshopphone = '" + emptyValue + "' WHERE barcode = " + orderlistviewermodell.getProductBarcode() + "");
        pst.executeUpdate();
        pst = conn.prepareStatement("DELETE FROM orderList WHERE productbarcode=?");
        pst.setString(1, orderlistviewermodell.getProductBarcode());
        pst.executeUpdate();
        pst.close();

    } catch (SQLException ex) {
        Logger.getLogger(StoreListViewerController.class.getName()).log(Level.SEVERE, null, ex);
    }

删除工作正常,但更新不是真的。它说我有语法错误并检查出来。

2 个答案:

答案 0 :(得分:3)

您的更新查询不需要TABLE

pst = conn.prepareStatement("UPDATE productList SET ordered = '" + falseValue + "', orderedshopphone = '" + emptyValue + "' WHERE barcode = " + orderlistviewermodell.getProductBarcode() + "");

答案 1 :(得分:0)

更新查询的基本语法是

update table_name set col1 = val1 , col2 = val2 ,... [where condition];

所以不需要 TABLE 关键字。

你的专栏应该是

pst = conn.prepareStatement("UPDATE productList SET ordered = '" + falseValue + "', orderedshopphone = '" + emptyValue + "' WHERE barcode = " + orderlistviewermodell.getProductBarcode() + "");