2016-09-26 60 views
-1

Iam在字符串qquery中出現錯誤,當我運行代碼Incorrect syntax near ')'.我的sql qquery在sqlserver中運行良好,他減去了產品數量。任何想法? TYcom.microsoft.sqlserver.jdbc.SQLServerException:錯誤的語法附近')'

錯誤日誌

at mylogin.Basket.makesales(Basket.java:160) 
    at mylogin.Basket.ReceiptActionPerformed(Basket.java:455) 
    at mylogin.Basket.access$100(Basket.java:23) 

這裏是我的代碼

 public void executeSQLQuery (String query,String message) { 
     Connection con =getConnection(); 
     Statement st; 
     try{ 
      st =con.createStatement(); 
      if((st.executeUpdate(query))==1) 
      { 
       con.commit(); 

       DefaultTableModel model=(DefaultTableModel)jTable_ProSales.getModel(); 
       model.setRowCount(0); 
       show_Basket_in_Jtable(); 
       JOptionPane.showMessageDialog(null,"Data "+message+" Succefully"); 
      }else{ 
       JOptionPane.showMessageDialog(null,"Data Not "+message+ "Error"); 
      } 

       }catch (Exception ex){ 
        ex.printStackTrace(); 
       } 
} 

操作按鈕

private void ReceiptActionPerformed(java.awt.event.ActionEvent evt) {           
     String query= "INSERT INTO Sales (Pro_Id ,Pro_Name,Sales_Quantity,Pro_Price) SELECT Pro_Id,Pro_Name,Sales_Quantity ,Pro_Price FROM Receipt"; 
    executeSQLQuery(query,"Inserted"); 
    String qquery= " UPDATE Products SET Pro_Quantity= Products.Pro_Quantity - Receipt.Sales_Quantity FROM Products INNER JOIN Receipt ON Products.Pro_Id = Receipt.Pro_Id)" ; 
     executeSQLQuery(qquery,"updated"); 
    } 
+4

您的查詢一個右括號,但沒有開口之一。 – Berger

+0

Ty非常有人正在運行 –

+0

如果問題得到解決,請關閉此問題。 –

回答

-1
private void ReceiptActionPerformed(java.awt.event.ActionEvent evt) {           
     String query= "INSERT INTO Sales (Pro_Id ,Pro_Name,Sales_Quantity,Pro_Price) SELECT Pro_Id,Pro_Name,Sales_Quantity ,Pro_Price FROM Receipt"; 
    executeSQLQuery(query,"Inserted"); 
    String qquery= " UPDATE Products SET Pro_Quantity= Products.Pro_Quantity - Receipt.Sales_Quantity FROM Products INNER JOIN Receipt ON Products.Pro_Id = Receipt.Pro_Id" ; 
     executeSQLQuery(qquery,"updated"); 
    } 
相關問題