有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

mysql SQL在Java中语法无效,但在Workbench中无效

为什么这条语句在workbench中运行良好,而在Java中运行不好

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

共 (1) 个答案

  1. # 1 楼答案

    事实证明,执行了多条语句(用分号分隔)。在JDBCMySQL中,您需要allowMultiQueries=true