Mybatis批量更新报错com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException
批量更新数据,非常简单的一段代码,硬是报错,插入的数据也能显示出来
List<User> userlist = new ArrayList<User>();
userlist.add(new User(1, "qq", "123132", "eee"));
userlist.add(new User(2, "3333", "123132", "rrrr"));
int i = usermapper.updateData(userlist);
<!-- 批量更新 -->
<update id="updateData" parameterType="list">
<foreach collection="list" item="item" separator=";">
update useres
<set>
uname=#{item.uname},pwd=#{item.pwd},realname=#{item.realname}
</set>
where
id=#{item.id}
</foreach>
</update>
[main] 2018/09/01 15:55:59 DEBUG (BaseJdbcLogger.java:132) - ooo Using Connection
[main] 2018/09/01 15:55:59 DEBUG (BaseJdbcLogger.java:132) - ==> Preparing: update useres SET uname=?,pwd=?,realname=? where id=? ; update useres SET uname=?,pwd=?,realname=? where id=?
[main] 2018/09/01 15:55:59 DEBUG (BaseJdbcLogger.java:132) - ==> Parameters: qq(String), 123132(String), eee(String),
### The error may involve com.bjsxt.user.entity.UserMapper.updateData-Inline
### The error occurred while setting parameters
### SQL: update useres SET uname=?,pwd=?,realname=? where id=? ; update useres SET uname=?,pwd=?,realname=? where 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 useres
SET uname='3333',pwd='123132',realname='rrrr'
where
id=' at line 6
at org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:23)
at org.apache.ibatis.session.defaults.DefaultSqlSession.update(DefaultSqlSession.java:150)
at org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:49)
at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:43)
at com.sun.proxy.$Proxy0.updateData(Unknown Source)
at com.bjsxt.user.test.TestMapper.main(TestMapper.java:41)
Caused by: 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 useres
SET uname='3333',pwd='123132',realname='rrrr'
where
id=' at line 6
最终,解决了问题如果连续执行多条sql语句 需要在url的后面 补充一个allowMultiQueries=true 即可
<property name="url" value="jdbc:mysql://localhost:3306/test?allowMultiQueries=true" />
[main] 2018/09/01 16:04:23 DEBUG (BaseJdbcLogger.java:132) - ooo Using Connection [com.mysql.jdbc.JDBC4Connection@5ce81285]
[main] 2018/09/01 16:04:23 DEBUG (BaseJdbcLogger.java:132) - ==> Preparing: update useres SET uname=?,pwd=?,realname=? where id=? ; update useres SET uname=?,pwd=?,realname=? where id=?
[main] 2018/09/01 16:04:23 DEBUG (BaseJdbcLogger.java:132) - ==> Parameters: qq(String), 123132(String), eee(String), 1(Integer), 3333(String), 123132(String), rrrr(String), 2(Integer)
[main] 2018/09/01 16:04:23 DEBUG (BaseJdbcLogger.java:132) - <== Updates: 1
1
[main] 2018/09/01 16:04:23 DEBUG (JdbcTransaction.java:66) - Committing JDBC Connection [com.mysql.jdbc.JDBC4Connection@5ce81285]
[main] 2018/09/01 16:04:23 DEBUG (JdbcTransaction.java:117) - Resetting autocommit to true on JDBC Connection [com.mysql.jdbc.JDBC4Connection@5ce81285]
[main] 2018/09/01 16:04:23 DEBUG (JdbcTransaction.java:85) - Closing JDBC Connection [com.mysql.jdbc.JDBC4Connection@5ce81285]
[main] 2018/09/01 16:04:23 DEBUG (PooledDataSource.java:332) - Returned connection 1558712965 to pool.
---------------------
作者:风泊月
来源:CSDN
原文:https://blog.csdn.net/hello_word2/article/details/82287895
版权声明:本文为博主原创文章,转载请附上博文链接!
Mybatis批量更新报错com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException的更多相关文章
- mysql报错com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException
一.问题 运行java代码时报如下的错误: You have an error in your SQL syntax;Cause:com.mysql.jdbc.exceptions.jdbc4.MyS ...
- hibernate 报错com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException
解释:JavaBean的主键类型只能是int类型,因为在映射关系配置是自动增长的,String类型是不能自动增长的,所以会报错.
- 求助:springboot调用存储过程并使用了pagehelper分页时报错com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException
存储过程如下: dao层的sql Controller层调用: html页面 没有使用pagehelper分页之前,可以正常使用 使用了pagehelper之后就报错 ### Error queryi ...
- jeecg启动报错“com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Could not create connection to database server.”的解决办法
在运行"maven build"-->"tomcat:run"之后,报如下错误: com.mysql.jdbc.exceptions.jdbc4.MySQ ...
- mybatis采坑之Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown column '?°?é?“é?“' in 'field list'
最后找到问题: 符号问题 修改之后正常
- [jnhs]hibernate只能创建一张/表不创建表com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Table 'kaihu.t_client_info' doesn't exist和org.hibernate.exception.SQLGrammarException: could not execute statement
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Table 'kaihu.t_client_info' doesn't exist ...
- 【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 erro ...
- mybatis批量更新报错
批量更新sql <update id="updateAutoAppraiseInfo" parameterType="Object"> <fo ...
- 5.7版本mysql查询报错:com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException:...this is incompatible with sql_mode=only_full_group_by
先瞧下日志: ### Error querying database. Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException ...
随机推荐
- ZT Android4.2蓝牙基础架构学习
Android4.2蓝牙基础架构学习 分类: Jellybean Bluetooth Bluetooth 2013-10-13 23:58 863人阅读 评论(3) 收藏 举报 androidblue ...
- Subversion、TortoiseSVN、Ankhsvn+VS使用
Subversion为版本控制软件的服务器端.VisualSVN Server 可以在Windows平台安装和管理全功能的Subversion server. TortoiseSVN为Subversi ...
- 洛谷 P4011 孤岛营救问题【最短路+分层图】
题外话:昨夜脑子昏沉,今早一调试就过了...错误有:我忘记还有墙直接穿墙过...memset初始化INF用错了数...然后手残敲错一个状态一直过不了样例...要是这状态去比赛我简直完了......or ...
- 【CF917D】Stranger Trees
题目 看题解的时候才突然发现\(zky\)讲过这道题啊,我现在怕不是一个老年人了 众所周知矩阵树求得是这个 \[\sum_{T}\prod_{e\in T}w_e\] 而我们现在的这个问题有些鬼畜了, ...
- javascript:typeof与instanceof区别
from:http://www.wxwdesign.cn/article/skills/javascript_typeof_instanceof.htm JavaScript中typeof和insta ...
- 3、JVM--垃圾回收期和内存分配策略(1)
前言: Java与C++之间有一堵由内存动态分配和垃圾收集技术所围成的“高墙”,墙外面的人想进去,墙里面的人却想出来. 3.1.概述 垃圾收集(Garbage Collection,GC),大部分人都 ...
- 模糊控制——(3)模糊自适应整定PID控制
1.原理 这种控制必须精确地确定对象模型,首先将操作人员(专家)长期实践积累的经验知识用控制规则模型化,然后运用推理便可对PID参数实现最佳调整. 自适应模糊PID控制器以误差e和误差变化ec作为输入 ...
- CAN总线布线规范
CAN总线布线规范 摘要:今天的CAN总线已从汽车电子慢慢渗透入工业自动化,医疗,铁路等众多领域.据我们的数据统计,客户在使用CAN总线时约80%的问题均是由总线布局布线不合理导致,今天我们就来扒一扒 ...
- iOS使用NSMutableAttributedString实现富文本小结
NSAttributedString NSAttributedString对象管理适用于字符串中单个字符或字符范围的字符串和关联的属性集(例如字体和字距).NSAttributedString对象的默 ...
- 大数据入门:Maven项目的创建及相关配置
目录 Maven项目的创建及相关配置 一.Maven的介绍 1.Maven是什么: 2.Maven作用: 3.Maven项目的目录结构: 4.Maven的三点坐标: 5.maven的pom文件: 6. ...