springboot批量修改报错,解决mybatis不支持sql批量执行的问题

基于springboot的项目,在进行批量更新操作时报错,但将打印出来的sql复制到mysql直接执行时,正常执行不报错

报错内容:

Error updating database.  Cause: java.sql.SQLSyntaxErrorException: 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 'update `t_chain_source_use_settle` SET SETTLE_STATE = 1
            WHERE PERIOD' at line 4
### The error may exist in file [D:\jxd\lulan\lulan-chain\target\classes\com\jxdinfo\hussar\sewageStation\dao\mapping\RawUseSettleMapper.xml]
### The error may involve com.jxdinfo.hussar.sewageStation.dao.RawUseSettleMapper.updateSettleStatu-Inline
### The error occurred while setting parameters
### SQL: update `t_chain_source_use_settle` SET SETTLE_STATE = 1             WHERE PERIOD = ? AND GOODS_CODE = ? AND BATCH = ?          ;              update `t_chain_source_use_settle` SET SETTLE_STATE = 1             WHERE PERIOD = ? AND GOODS_CODE = ? AND BATCH = ?          ;
### Cause: java.sql.SQLSyntaxErrorException: 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 'update `t_chain_source_use_settle` SET SETTLE_STATE = 1
            WHERE PERIOD' at line 4
; bad SQL grammar []; nested exception is java.sql.SQLSyntaxErrorException: 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 'update `t_chain_source_use_settle` SET SETTLE_STATE = 1
            WHERE PERIOD' at line 4] with root cause

java.sql.SQLSyntaxErrorException: 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 'update `t_chain_source_use_settle` SET SETTLE_STATE = 1
            WHERE PERIOD' at line 4

原因:

         Mybatis映射文件中的sql语句默认是不支持以" ; " 结尾的,也就是不支持多条sql语句的执行

解决方案:

        在连接mysql的url上加 &allowMultiQueries=true 

url: jdbc:mysql://ip:端口号/数据库?autoReconnect=true&useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false&serverTimezone=UTC&allowMultiQueries=true 

 allowMultiQueries=true表示可以在sql语句后携带分号,即可以实现多语句执行

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值