嗨,我目前正在開發一個應用程序來維護某個工廠的股票,我無法將訂單插入數據庫..我嘗試修復這個我自己的,但我不能這樣如果任何人可以幫助我很高興。Java MySQLSyntaxErrorException
因此,這裏是我的錯誤
com.mysql.jdbc.exceptions.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'order (Add_Order_PID,Customer_idCustomer,Items_idItems,User_idUser,Color,Leather' at line 1
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:936)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2985)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1631)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1723)
at com.mysql.jdbc.Connection.execSQL(Connection.java:3250)
at com.mysql.jdbc.Statement.executeUpdate(Statement.java:1355)
at com.mysql.jdbc.Statement.executeUpdate(Statement.java:1270)
at DB.Save_Update_Delete(DB.java:32)
at New_Order1.jButton4ActionPerformed(New_Order1.java:605)
at New_Order1.access$800(New_Order1.java:23)
at New_Order1$9.actionPerformed(New_Order1.java:389)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2018)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2341)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:402)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:259)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:252)
at java.awt.AWTEventMulticaster.mouseReleased(AWTEventMulticaster.java:289)
at java.awt.Component.processMouseEvent(Component.java:6505)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3321)
at java.awt.Component.processEvent(Component.java:6270)
at java.awt.Container.processEvent(Container.java:2229)
at java.awt.Component.dispatchEventImpl(Component.java:4861)
at java.awt.Container.dispatchEventImpl(Container.java:2287)
at java.awt.Component.dispatchEvent(Component.java:4687)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4832)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4492)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4422)
at java.awt.Container.dispatchEventImpl(Container.java:2273)
at java.awt.Window.dispatchEventImpl(Window.java:2719)
at java.awt.Component.dispatchEvent(Component.java:4687)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:729)
at java.awt.EventQueue.access$200(EventQueue.java:103)
at java.awt.EventQueue$3.run(EventQueue.java:688)
at java.awt.EventQueue$3.run(EventQueue.java:686)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:87)
at java.awt.EventQueue$4.run(EventQueue.java:702)
at java.awt.EventQueue$4.run(EventQueue.java:700)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:699)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:242)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:161)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:150)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:146)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:138)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:91)
我的代碼是
for (int i = 0; i < jTable1.getRowCount(); i++) {
String $Name = "", $Color = "", $Leather = "", $s38 = "", $s39 = "", $s40 = "", $s41 = "", $s42 = "", $s43 = "", $s44 = "", $s45 = "", $s46 = "", Total = "", ItemId = "";
$Name += jTable1.getValueAt(i, 0)+"";
$Color += jTable1.getValueAt(i, 1)+"";
$Leather += jTable1.getValueAt(i, 2)+"";
$s38 += jTable1.getValueAt(i, 3)+"";
$s39 += jTable1.getValueAt(i, 4)+"";
$s40 += jTable1.getValueAt(i, 5)+"";
$s41 += jTable1.getValueAt(i, 6)+"";
$s42 += jTable1.getValueAt(i, 7)+"";
$s43 += jTable1.getValueAt(i, 8)+"";
$s44 += jTable1.getValueAt(i, 9)+"";
$s45 += jTable1.getValueAt(i, 10)+"";
$s46 += jTable1.getValueAt(i, 11)+"";
Total += jTable1.getValueAt(i, 12)+"";
ItemId += jTable1.getValueAt(i, 13)+"";
DB.Save_Update_Delete("insert into order (Add_Order_PID,Customer_idCustomer,Items_idItems,User_idUser,Color,Leather,s38,s39,s40,s41,s42,s43,s44,s45,s46,Total) values ('"+pid+"','"+Integer.parseInt(customerID.getText())+"','"+Integer.parseInt(ItemId)+"','"+Integer.parseInt(UserID.getText())+"','"+$Color+"','"+$Leather+"','"+$s38+"','"+$s39+"','"+$s40+"','"+$s41+"','"+$s42+"','"+$s43+"','"+$s44+"','"+$s45+"','"+$s46+"','"+Total+"')");
}
使用準備好的語句 –
詳細說明「使用準備好的語句」:準備好的語句更有效,並且對SQL注入攻擊是安全的,而連接的SQL字符串(在您使用時)不是。 –
@FrankSchmitt是他們在PreparedStatement中的任何方式來添加where條款下的條件,或者我需要首先確定所有條件,然後單步執行PreparedStatement。對不起,這是關閉的話題。 – guptakvgaurav