请帮助我找出如何允许mysql连接器j定义用户变量并使此代码有效:
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);");
Run Code Online (Sandbox Code Playgroud)
现在它引发了一个异常:
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
Run Code Online (Sandbox Code Playgroud)
我知道在.net中你可以在连接字符串中定义"允许用户变量=真"选项.如何在java中做到这一点?
我发现了如何使它工作.只需设置datasource属性allowMultiQueries = true
jdbc:mysql://localhost:3306/DBS?allowMultiQueries=true
Run Code Online (Sandbox Code Playgroud)