tags:

views:

22

answers:

1

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.

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

String qery="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  A: 

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)
Daniel Vassallo
Thanks it worked.