-1

I got the error.

org.springframework.jdbc.BadSqlGrammarException: 
### Error updating database.  Cause: 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 (productId, address, productName, price, imageUrl) VALUES ('000', 'address' at line 1
### The error may involve Order.insert-Inline
### The error occurred while setting parameters
### SQL: INSERT INTO order (productId, address, productName, price, imageUrl) VALUES (?, ?, ?, ?, ?)
### Cause: 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 (productId, address, productName, price, imageUrl) VALUES ('000', 'address' at line 1
; bad SQL grammar []; nested exception is 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 (productId, address, productName, price, imageUrl) VALUES ('000', 'address' at line 1
    at 

I looked at my xml as the error log told me.

<insert id="insert" parameterType="com.whiuni.fastshop.vo.OrderVO">
        INSERT INTO order (productId, address, productName, price, imageUrl) VALUES (#{productId}, #{address}, #{productName}, #{price}, #{imageUrl})
</insert>

Could anyone tell me what the error is? Thank you

lee1707
  • 15
  • 6
  • Please read & act on [mcve]. Finding minimal code with your error involves finding code with no error. PS The FK productId is string. What is the type of the PK it references? PS 6 columns. PS It seems unlikely that this is not a faq. Please always google many clear, concise & specific versions/phrasings of your question/problem/goal with & without your particular strings/names & read many answers. Add relevant keywords you discover to your searches. If you don't find an answer then post, using one variant search for your title & keywords for your tags. See the downvote arrow mouseover text. – philipxy Sep 02 '18 at 18:46
  • @philipxy Thank you. I changed question. – lee1707 Sep 03 '18 at 02:07

1 Answers1

0

order is a reserved word in mysql, change the table name or surround it with single-quotes

INSERT INTO 'order' (productId, address, productName, price, imageUrl) ...
Joakim Danielson
  • 43,251
  • 5
  • 22
  • 52