2013-10-26 37 views
1

我有查詢MySQL查詢工作在phpMyAdmin,但沒有在Java中

INSERT INTO tests2 (`name`, `val1`, `val2`, `val3`, `rotation~time`, `rotation~messages~countdown_format`, `rotation~messages~messages`) VALUES ('Testing', 'Test', 'false', '0', '21', 'Value', '[[Value 1, Value 2]]') 

它工作在phpMyAdmin的罰款,但它給出了一個例外:

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 ')' at line 1 

在Java中調用時使用

statement.execute(query); 

(我用這個方法創建連接:)

 connection = DriverManager.getConnection(getJDBCString(settings.host(), settings.port(), settings.database()), settings.username(), settings.password()); 
     statement = connection.createStatement(); 

出了什麼問題?

編輯

我打算有整數和布爾值保存爲字符串

我也試過換了墳墓(`)「和」

+2

嘗試在java代碼中用'''替換'(重音符號,或者其他)。 – Izmaki

+2

首先,停止在整數字段中添加撇號,它們用於字符串。其次,爲Java代碼提供查詢。 –

+0

@MostyMostacho它是我的意圖,作爲字符串存儲整數 –

回答

0

我猜測查詢的值是用Java變量填充的,如果是的話,我會檢查'[[Value 1,Value 2]]'是否正確填充了一個字符串值。安伏在錯誤消息中提供的查詢的一部分,所以...

the right syntax to use near ')' 

意味着問題可能是任一'[[值1,值2]]')rotation~messages~messages

相關問題