您好我正在开发一个应用程序来维护某个工厂的库存,我无法将订单插入数据库..我尝试修复这个我自己但我不能这样,如果任何人可以帮助这个我很高兴。
所以这是我的错误
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+"')");
}
答案 0 :(得分:0)
您使用引号(&#39;&#39;)
插入int值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+"')"
);
最好在此处使用PreparedStatement和learn
答案 1 :(得分:0)
检查Add_Order_PID是否为整数。如果是整数,请不要加双引号。
对于任何数字数据类型,请勿放入双引号..
最好使用PreparedStatement进行插入
答案 2 :(得分:0)
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 ('8','1','2','1','Black','Leather 1','2','0','0','0','0','0','0','0','0','2')
直接在mysql控制台中试用你的sql语句。它将为您提供有关真正问题的更多信息。也许你违反了一些外键。