问题描述
在MyBatis的Mapper中,想执行多条SQL语句,这些语句已经在SQL的客户端中执行过没有任何问题的,但是写在Mapper中执行后,却总是报错,报错可能是(这是在Oracle数据库的报错,MySQL可能也是类似的):
1)invalid character<EOL><EOL>
2); bad SQL grammar []; nested exception is java.sql.SQLSyntaxErrorException: ORA-00933: SQL 命令未正确结束
解决办法
MySQL下:
数据连接url开启多条语句处理
在url后面加入&allowMultiQueries=true
jdbc:mysql://127.0.0.1:3306/user?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&allowMultiQueries=true //每条sql以分号结束 <update id="someUpdateFunction"> delete from table1 where id = 1; update table2 where id = 2; <update>
Oracle下的处理方式:
在多条SQL语句的前后增加begin和end; 注意end后面有个分号。
//每条sql以分号结束,end也是分号结束 <update id = "someUpdateFunction"> begin delete from table1 where id = 1; update table2 where id = 2; end; <update>
文章评论