当前位置: 首页 >数据库 > mybatis批量更新不同参数多条语句带分号update报错的解决方案

mybatis批量更新不同参数多条语句带分号update报错的解决方案

问题

在走接口的时候,需要使用mybtatis的批量更新,偷了个懒使用Foreach的形式拼接多个sql语句进行更新。结果在执行到这个sql的时候update一直报错

### 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 xxxxxxxxxxxxxxxxx at line 1### The error may exist in xxxxxxxxx.java (best guess)### The error may involve xxxxxxxxxx.someaction-Inline### The error occurred while setting parameters### SQL: update xxxxxxxxxxxxxxx### 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 invoice_check set company_id = '1132',pch = '2021050610191505316062112345' at line 1\n; 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 xxxxxxxxxxxxxxx at line 1

  

让我检查update左侧的语句,而左侧的语句是;,怎么会出问题,于是将sql打印出来查看

update xxx set xxx = xxx where id = x ; update xxx set xxx = xxx where id = x 

  

直接扔到navicat里执行无误,但是在程序中就挂掉了

解决方案

在jdbc中加上一句

 

&allowMultiQueries=true

  

就解决了
例如

jdbc:mysql://localhost/test?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8&useAffectedRows=true&allowMultiQueries=true

  

 

作者:xingmeng1
来源链接:https://www.cnblogs.com/xingmeng63/p/17259083.html

版权声明:
1、JavaClub(https://www.javaclub.cn)以学习交流为目的,由作者投稿、网友推荐和小编整理收藏优秀的IT技术及相关内容,包括但不限于文字、图片、音频、视频、软件、程序等,其均来自互联网,本站不享有版权,版权归原作者所有。

2、本站提供的内容仅用于个人学习、研究或欣赏,以及其他非商业性或非盈利性用途,但同时应遵守著作权法及其他相关法律的规定,不得侵犯相关权利人及本网站的合法权利。
3、本网站内容原作者如不愿意在本网站刊登内容,请及时通知本站(javaclubcn@163.com),我们将第一时间核实后及时予以删除。





本文链接:https://www.javaclub.cn/database/118574.html

标签:SQL_syntax
分享给朋友:

“mybatis批量更新不同参数多条语句带分号update报错的解决方案” 的相关文章

一文带你了解MySQL基础 2022年05月15日 09:35:43
MySQL主从复制 2022年05月17日 21:34:56
Mysql查询某字段值重复的数据 2022年06月11日 19:39:22
关于mysql数据库连接异常处理 2022年06月12日 19:21:20
mysql查询结果保留2位小数不够补0 2022年06月12日 20:39:53
MySQL查询表中的数据是否存在 2022年06月13日 13:46:57
MySQL查询指定行的记录 2022年06月14日 06:02:58
mysql查询数据库的名称 2022年06月17日 22:38:25