0

I am getting a syntax error in the following lines. I am not familiar with mysql so any pointers will be helpfull

 ps = con.prepareStatement("INSERT INTO order(status,ordered_on,total_price,user_id) "
                + " VALUES(?,?,?,?)");

        ps.setString(1,"pending");
        ps.setTimestamp(2,date);
        ps.setDouble(3,total_price);
        ps.setInt(4,ID);

The error was MySQL server version for the right syntax to use near 'order(status,ordered_on,total_price,user_id) VALUES('pending','2017-03-22 04:08' at line 1

3
  • Try removing the concatenation in the query to start. If that doesn't work try inserting just status (remove rest of vars to simplify things) Commented Mar 21, 2017 at 22:53
  • you have two spaces between ") VALUES" and no space after values Commented Mar 21, 2017 at 22:54
  • order is a reserved word. Enclose it in "`" if you are referring to a table with the same name like `order`. Commented Mar 21, 2017 at 22:58

1 Answer 1

1

The problemis that order is a reserved keyword for mysql ; so you have two solutions at your disposal 1 : if you are required some raison to use that work in case you case use backtick escapes `order`
2 : you can use plural for the tables name like orders

    ps = con.prepareStatement("INSERT INTO `order`(status,ordered_on,total_price,user_id) "
            + " VALUES(?,?,?,?)");

    ps.setString(1,"pending");
    ps.setTimestamp(2,date);
    ps.setDouble(3,total_price);
    ps.setInt(4,ID);

This is q link to the mysal reserved keywords

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

Comments

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.