0

I am using MYSQL 5.1, I am trying to write an insert statement in my java class. It sounds very simple but i tried and getting exception. I am sure there is a syntax error with my code. below is the snippet could any one help me out here.

  • ID is in primary key
  • atm_ID is varchar
  • trasn_id is varchar
  • sysDate is Date
  • rest is int

Please help me out.

Error:

SQL statement is not executed!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 '£10, £20, £50, £100, trans_Id) VALUES (7,'hello','hello','2','2','2','2','2','he' at line 1`

Code:

String query = "INSERT INTO atm_data (ID,atm_Id, sysDate, availBalance, £10, £20, £50, £100, trans_Id) VALUES (7,'hello','2010-09-15 01:20:06','2','2','2','2','2','hello')";
1
  • 2
    I'd advise changing your column names in such a way they only contain alphanumeric characters and underscores. While technically you can use any character in table name, it's often cause of problems and requires special treatment. Commented Sep 6, 2010 at 16:47

1 Answer 1

1

It looks like you simply need to escape the column names that start with £ with backticks:

INSERT INTO atm_data (ID, ... `£10`, `£20`, `£50`, `£100` ...

Test case:

CREATE TABLE tb (`£10` int);
Query OK, 0 rows affected (0.05 sec)

INSERT INTO tb (£10) VALUES (10);
ERROR 1064 (42000): 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 '?10) VALUES (10)' at line 1

INSERT INTO tb (`£10`) VALUES (10);
Query OK, 1 row affected (0.00 sec)
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.