我正在使用MYSQL 5.1,我試圖在我的java類中編寫插入語句。這聽起來很簡單,但我試圖得到例外。我相信我的代碼有一個語法錯誤。下面是任何一個幫助我在這裏的片段。Mysql插入命令語法
- ID是主鍵
- atm_ID爲varchar
- trasn_id爲varchar
- SYSDATE是日期
- 其餘爲int
請幫助我。
錯誤:
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 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')";
我建議改變你的列名,使它們只包含字母數字字符和下劃線。雖然在技術上可以使用表名中的任何字符,但通常會導致問題並需要特殊處理。 – Mchl 2010-09-06 16:47:38