源地址 http://quabr.com/22829539/mybatis-batch-update-exception
使用如下Mybatis map xml文件
<update id="updateTestcaseNodeBatch" parameterType="List">
<foreach collection="list" item="nodeVO" separator=";">
UPDATE testcase_node
<set>
name=#{nodeVO.name},
version=#{nodeVO.version},
description=#{nodeVO.description},
last_modify_user=#{nodeVO.createUser},
last_modify_time=#{nodeVO.createTime}
</set>
<where>
object_id=#{nodeVO.objectId} AND root_id=#{nodeVO.rootId}
</where>
</foreach>
</update>
出错信息:
### The error may involve com.hirain.testmanagement.mapper.TestcaseNodeMapper.updateTestcaseNodeBatch-Inline
### The error occurred while setting parameters
### SQL: UPDATE testcase_node SET name=?, version=?, description=?, last_modify_user=?, last_modify_time=? WHERE object_id=? AND root_id=? ; UPDATE testcase_node SET name=?, version=?, description=?, last_modify_user=?, last_modify_time=? WHERE object_id=? AND root_id=?
### 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 testcase_node
SET name='Türstatus',
version=4,
' at line 8
; 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 testcase_node
SET name='Türstatus',
version=4,
' at line 8
at org.springframework.jdbc.support.SQLErrorCodeSQLExceptionTranslator.doTranslate(SQLErrorCodeSQLExceptionTranslator.java:233)
仔细检查 map文件 和数据库表字段没有错误
最终结果是因为 配置的 mysql jdbc 链接字符串 默认不支持一次性执行多个sql 语句;
但是在我们的 update map中需要执行多个 update语句。
最后加上参数 "allowMultiQueries" 设置为true 如下:
<property name="jdbcUrl" value="jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=utf-8&allowMultiQueries=true" />
问题解决!
分享到:
相关推荐
Mybatis批量foreach merge into的用法,这是介绍Mybatis批量foreach merge into的用法的文档
主要介绍了mybatis执行批量更新batch update 的方法,提供oracle和mysql两种方法,非常不错,需要的朋友参考下
Mybatis Plus 自定义批量插入或批量更新(根据唯一索引)
在获取update操作的返回值时遇到了一个问题,似乎 Mybatis 进行 update 操作得到的 int 返回值并不是影响的行数,下面通过本文给大家分享Mybatis Update操作返回值问题,需要的朋友参考下吧
MyBatis批量插入,效率经测试,1000条数据,批量插入和单条插入,执行效率至少快一倍,送上源码,供参考学习
使用mybatis写sql,需要动态更新对象数据,每次需要更新的字段不同,为了防止null空异常,就需要用动态sql了,下面给大家分享一段代码关于mybatis动态update,需要的朋友参考下
主要介绍了基于mybatis batch实现批量提交大量数据,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下
今天小编就为大家分享一篇关于MyBatis通过BATCH批量提交的方法,小编觉得内容挺不错的,现在分享给大家,具有很好的参考价值,需要的朋友一起跟随小编来看看吧
本文给大家介绍Oracle+Mybatis的foreach insert批量插入报错的快速解决办法,非常不错,具有参考借鉴价值,感兴趣的朋友参考下吧
主要介绍了Mybatis中使用updateBatch进行批量更新的相关资料,有逐条更新,sql批量更新等,具体实例代码大家参考下本
MyBatis防止批量更新1
测试mybatis里foreach用法,使用于list,array,map,怎么凑字数
NULL 博文链接:https://hzs0502030128.iteye.com/blog/2254585
压缩包有eclipse包文件和操作步骤word文档 mybatis数据操作(增删改查+批量操作)
跨库批量插入
如何在Mybatis和XML中的foreach中批处理Sqlsession 应用于mybatis批处理测试的技术如下: 使用开源 版本 Java 1.7 春天 4.1.5 摇动 2.2.1 Mybatis 3.2.8 功能细节 mybatis-batch-test在test_book表中堆积了...
SpringMVC + Mybatis框架简单增删改查功能实现
文档中主要说明:(1)多表联合查询步骤,快捷便利;(2)数据批量插入,以及相关的案例,节省运行资源。
mybatis 框架批量增删改代码 示例 含java与xml
Java实现使用Mybatis将数据批量插入到Oracle数据库,并且可以使用Oracle序列来生成主键