1

Why does this statement work fine in workbench but not in Java.

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

In Java I get

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
6
  • Those quotes look weird. Shouldn't it be " instead of two single quotes? Commented Jun 24, 2014 at 15:10
  • have you tried simplifying the query to isolate the part causing the error? Commented Jun 24, 2014 at 15:10
  • And do you know what JDBC uses as delimiter? Commented Jun 24, 2014 at 15:11
  • I had thought a single quote should be escaped by a single quote when already inside single quotes. Isn't that true? Commented Jun 24, 2014 at 15:11
  • I haven't seen it before. Could you try to escape these quotes not with other quotes but with backslashes? Commented Jun 24, 2014 at 15:16

1 Answer 1

1

It turned out to be the fact that multiple statements were being executed (separated by semicolons). In JDBC MYSQL you need allowMultiQueries=true

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.