2014-06-24 13 views
1

爲什麼此語句在工作臺中工作正常,但在Java中不起作用。SQL在Java中無效,但在Workbench中不存在語法

SET @sqlstmt := IF(@exist <= 0, 'select ''INFO: Key does not exist.''', 'ALTER TABLE `SOMETABLE` DROP FOREIGN KEY `SOMEKEY`'); 

在Java中,我得到

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 'SET @sqlstmt := IF(@exist <= 0, 'select ''INFO: Key does not exist.''', 'ALTER ' at line 1 
+0

這些引號看起來很奇怪。不是'''而不是兩個單引號嗎? – 11684

+0

你試過簡化查詢來隔離導致錯誤的部分嗎? – djechlin

+0

你知道JDBC用作分隔符麼? – 11684

回答

1

它竟然是,正在執行多個語句的事實(由分號分隔)。在JDBC MYSQL中你需要allowMultiQueries=true

相關問題