1
PreparedStatement ps;
String query = "INSERT INTO order (table_id,dish_id,price,count) VALUES (?,?,?,?)";
try {
    con = DBHelper.getCon();
    ps = con.prepareStatement(query);
    ps.setInt(1, order.getTable_id());
    ps.setInt(2, order.getDish_id());
    ps.setInt(3, order.getPrice());
    ps.setInt(4, order.getCount());
    result = ps.executeUpdate();
...

I have error in executeUpdate() method. It shows

java.sql.SQLSyntaxErrorException: 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 error.

How can I fix it?

1
  • How did you create table ORDER? I tried and got an error. See this db fiddle Commented Oct 6, 2020 at 5:35

1 Answer 1

1

In your SQL statement, order is understood as the incomplete SQL keyword ORDER BY.

I would suggest you to rename the tablename to orders to remove the ambiguity.

Sign up to request clarification or add additional context in comments.

5 Comments

According to your answer, it would be impossible to create table ORDER in the first place, wouldn't it?
I would suggest you to read and follow SQL naming conventions to avoid such discrepancies. It's not about being impossible, but defining everything in an unambiguous and absolute manner.
Thanks for your suggestions.It works.Now there is no error.
@EmilyWatson Why did you remove my accepted answer in the other thread? could you give me an upvote?
I am new user of Stackoverflow. Sorry. I will upvote.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.