mybatis批量更新update-设置多个字段值 报错 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
mybatis批量更新update-设置多个字段值
mybatis由于简单易用性得到大家的认可和使用
但是在批量更新操作中,网上介绍的貌似不全,正好今天做个记录,大家一起进步
在实际项目开发过程中,常有这样的需求:根据ids更新表的某一个字段值,这时的sql语句是:
- public interface IStaffDao {
- void batchUpdate(@Param("list") List<Long> list);
- }
- <select id="getStaffsByIds" resultMap="staff_Mapper">
- update staff set status = 0 where id in
- <foreach collection="list" item="item" index="index" open="(" separator="," close=")" >
- #{item}
- </foreach>
- ORDER BY id
- </select>
还有一种情况:根据ids更新表的多个值,并且每个id对应的值也不一样,这时上述语句已经满足不了需求,需要另一种批量更新sql语句
- public interface IStaffDao {
- void batchUpdate(@Param("list") List<Staff> list);
- }
- <update id="batchUpdate" parameterType="java.util.List" >
- <foreach collection="list" item="item" index="index" separator=";">
- UPDATE staff set count = #{item.count} , code = #{item.code} , invalid_time = #{item.time} WHERE id = #{item.id}
- </foreach>
- </update>
由于这种批量更新是一次执行多个update语句,所以mybatis需要额外的配置:
在spring.datasource.url后加上allowMultiQueries=true
如:jdbc:mysql://10.10.20.36:3306/test?allowMultiQueries=true
否则,在执行sql语句时,会报下面的错误
- [org.apache.ibatis.session.defaults.DefaultSqlSession@76a2f910]
- org.springframework.jdbc.BadSqlGrammarException:
- ### Error updating database. Cause: 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 b_email_msg_remind
- SET send_status = 1, send_email_code='abc@abc.abc'' at line 6
- ### The error may involve com.hhsoft.sectionservice.model.persistence.EmailMapper.updateEmailTasks-Inline
- ### The error occurred while setting parameters
- ### Cause: 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 staff
- SET status = 1, send_email_code='abc@abc.abc';<span style="font-family: Helvetica, Tahoma, Arial, sans-serif;">update sta<span style="font-size:10px;">ff SET status = 2,</span> send_email_code='test@qq.com' </span>' at line 6
- ; bad SQL grammar []; nested exception is 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 b_email_msg_remind
- SET send_status = 1, send_email_code='abc@abc.abc'' at line
mybatis批量更新update-设置多个字段值 报错 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的更多相关文章
- MySql 执行语句错误 Err] 1064 - 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
关于用Power Designer 生成sql文件出现 错误 [Err] 1064 - You have an error in your SQL syntax; check the manual ...
- 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 '
mysql中如果字段使用了关键字,在插入和更新时会提示 You have an error in your SQL syntax; check the manual that corresponds ...
- 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 'varchar(255), sort integer not null
you have an error in your SQL syntax; check the manual that corresponds to your MySQL server version ...
- ERROR: 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 'type=InnoDB' at line 7
问题: 使用hibernate4.1.1,数据库使用mysql5.1.30,使用hibernate自动生成数据库表时,hibernate方言使用org.hibernate.dialect.MySQLI ...
- 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数据库时打印出来的异常: ### Error updating database. Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLSynt ...
- 1064 - 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 'groups)VALUES('1','hh','hh@163.com','Boss')' at line 1
mysql8.0版本 在已存在的表里插入一条数据 insert INTO api_user(id,username,email,groups)VALUES('1','hh','hh@163.com', ...
- C# Mysql 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 ????
有几年没用过MySql数据了,今天在使用C#访问MySql数据库时出现了一个小插曲. 错误提示: You have an error in your SQL syntax; check the man ...
- 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 'like '%逸%'' at line 1
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE mapper PUBLIC "-/ ...
- 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 'group t1,customer t2
### SQL: select t1.gid,t1.gname,t1.gvalue,t1.gtype, t1.gaddress,t1.gmembers, t1.gcode,t1.gphone, t2. ...
随机推荐
- JSONArray
action层 js alert(result); result返回的是[{"countryId":"","id":"1&qu ...
- WDA-4-ALV按钮&ICON
1.ICON图标 AccessControlledArea (14x14) Activate (14x14) Active (14x14) AdaptationTechnical (14x14) Ad ...
- Zookeeper 在Linux系统的安装
注册中心Zookeeper 官方推荐使用 zookeeper 注册中心.注册中心负责服务地址的注册与查找,相当于目录服务,服务提供者和消费者只在启动时与注册中心交互,注册中心不转发请求,压力较小. Z ...
- java split函数结尾空字符串被丢弃的问题
参考: http://yinny.iteye.com/blog/1750210 http://www.xuebuyuan.com/1692988.html java中的split函数用于将字符串分割为 ...
- 【x】 PAT/BasicLevel_C++/1002. 写出这个数 (20).cpp
C++中的to_string()函数[C++11支持] - Bravo Yeung-羊较瘦之自留地 - CSDN博客https://blog.csdn.net/lzuacm/article/detai ...
- [ SHELL编程 ] shell编程中数值计算方法实例
SHELL编程中经常会涉及到数值计算,有时候对于这些计算命令使用场景容易忘记或者混淆,这里针对常用的命令做个总结.主要包括let.bc.expr.(())等. 1.let 使用格式:let 表达式,表 ...
- python实现根据目标字符串修改一下行
需求: 根据source和dest两个文件,找出新增的命令行,然后在xml文件中根据命令修改id 输入souce: ADD 100 SUB 200 输入dest: MUL 300 DIV 400 AD ...
- Myeclipse2017 安装反编译插件和SVN插件
亲测有效 2018年1月22日10:36:33 https://www.cnblogs.com/liuyk-code/p/7519886.html
- Delphi中For In 语法应用实例
一.遍历 TStrings var List: TStrings; s: string; begin List := TStringList.Create; List.CommaText := 'aa ...
- ckeditor使用说明
2015-08-17 15:42热心网友最快回答 一.使用方法:1.在页面<head>中引入ckeditor核心文件ckeditor.js<script type="t ...