sql语法错误MySQLSyntaxErrorException

时间:2013-11-26 12:13:30

标签: java mysql sql jdbc

String sql = "INSERT INTO order " + "(customerid, pant, shirt, date) " 
  + "VALUES ('"  + jTextField1.getText() + "','" + jTextField2.getText() 
  + "','" + jTextField3.getText() + "','" + jTextField4.getText() + "')";

尝试此操作时,出现以下错误:

com.mysql.jdbc.exceptions.jdbc4.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 (customerid, pant, shirt, date) VALUES ('10','2','3','26')' at line 1
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method).

2 个答案:

答案 0 :(得分:4)

您需要使用反引号{/ 1>来reserved words转义order

INSERT INTO `order` (customerid, ...

除此之外,我建议使用准备好的陈述

答案 1 :(得分:0)

表名“订单”是保留字,因此请更改表名并试用。