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

When tried this, I got the following error:

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).
1
  • This code is just begging for a SQL injection attack. Do not use string concatenation for SQL, use PreparedStatements and query parameters for the love of humanity. Commented Nov 26, 2013 at 14:53

2 Answers 2

4

You need to escape reserved words like order with backticks

INSERT INTO `order` (customerid, ...

Besides that I recommend using Prepared Statements.

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

Comments

0

Table name "order" is reserve word so please change table name and try it.

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.