2017-05-27 45 views
2

從2小時起,我正在處理UPDATE TABLE語句,它總是給出語法錯誤。我做了這個:更新表的語法錯誤表

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); 
    } 

的刪除工作正常,但更新不是真的。它說我有語法錯誤並檢查出來。

+0

你已經使用PrepapredStatement你爲什麼不使用'?',以避免SQL注入,或語法注射 –

回答

3

您的更新查詢有TABLE,不需要。

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

更新查詢的基本語法

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

所以沒有必要關鍵的詞。

你行應

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