【mybatis】mybatis进行批量更新,报错:com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right
使用mybatis进行批量更新操作:
报错如下:
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: 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
goods g
SET
update_date = '2019-03-19 17:16:05.918',
updat' at line 28
但是检查了以后,28行并没有错误
使用【https://www.cnblogs.com/sxdcgaq8080/p/9100178.html】 打印了sql,发现sql如下,也没有问题:

UPDATE goods
SET update_date = '2019-03-19 17:12:30',
update_id = 'defUserId',
enabled = 1,
NAME = '李钢的屏幕维修服务',
py_all = 'ligangdepingmuweixiufuwu',
py_head = 'lgdpmwxfw',
outer_code = '345345345345',
mnemonic_code = '',
del_flag = 0,
enabled_flag = 1,
goods_type_uid = 'a5cd4e8cc75456e7',
url = '',
bar_cide = '',
sale_price = NULL,
integral = 0,
scan_name = '李钢的屏幕维修服务',
brand_uid = '01',
en_name = '李钢的屏幕维修服务'
WHERE
outer_id = '345345345345'
AND tenement_id = 'test_tenement_123';
UPDATE goods
SET update_date = '2019-03-19 17:12:30',
update_id = 'defUserId',
enabled = 1,
NAME = '黑莓798',
py_all = 'heimei798',
py_head = 'hm798',
outer_code = '453975973361094656',
mnemonic_code = '',
del_flag = 0,
enabled_flag = 1,
goods_type_uid = 'a5cd4e8cc75456e7',
url = '',
bar_cide = '',
sale_price = NULL,
integral = 0,
scan_name = '黑莓798',
brand_uid = '01',
en_name = '黑莓798'
WHERE
outer_id = '453975973361094656'
AND tenement_id = 'test_tenement_123';
UPDATE goods
SET update_date = '2019-03-19 17:12:30',
update_id = 'defUserId',
enabled = 1,
NAME = '测试商品',
py_all = 'ceshishangpin',
py_head = 'cssp',
outer_code = 'CS001',
mnemonic_code = '',
del_flag = 0,
enabled_flag = 1,
goods_type_uid = 'a5cd4e8cc75456e7',
url = '',
bar_cide = '',
sale_price = NULL,
integral = 0,
scan_name = '测试商品',
brand_uid = '01',
en_name = 'test
product'
WHERE
outer_id = 'CS001'
AND tenement_id = 'test_tenement_123'
报错原因:
是因为spring boot配置文件中,关于数据库的连接配置,并没有允许进行批量更新的操作
解决方法:
将数据库配置修改为
jdbc.url=jdbc:mysql://127.0.0.1:3306/datebase?useUnicode=true&characterEncoding=UTF-8&autoReconnect=true&allowMultiQueries=true 新增了 &allowMultiQueries=true 意为 允许批量更新
需要注意的是:
加了&allowMultiQueries=true 意为 允许批量更新 但是此时如果再想在spring boot中运行mybatis的时候想打印出来sql,就已经不起作用了。 此时按照 https://www.cnblogs.com/sxdcgaq8080/p/9100178.html 配置的,在spring boot中打印sql语句,就无效了
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY
· 【自荐】一款简洁、开源的在线白板工具 Drawnix
2018-03-20 【flyway】Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'flywayInitializer' def
2017-03-20 【java】实体类中 Set<对象> 按照对象的某个字段对set排序