MySql j connector allows user variables

Please help me learn how to enable the mysql connector j to define user variables and make this code valid:

Statement s = conn.createStatement(); s.executeQuery ("set @categoryId := (Select CategoryId from categories order by CategoryId desc LIMIT 1);\n" + "set @categoryId := IF(@categoryId is Null, 1, @categoryId);"); 

now it throws an exception:

 MySQLSyntaxErrorException occured : 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 @categoryId := IF(@categoryId is Null, 1, @categoryId)' at line 2 

I know that in .net you can define the option "Allow user variables = true" in the connection string. How to do this in java?

+4
source share
1 answer

I learned how to make it work. Just set the datasource property allowMultiQueries = true

  jdbc:mysql://localhost:3306/DBS?allowMultiQueries=true 
+8
source

Source: https://habr.com/ru/post/1341800/


All Articles