批量更新数据,非常简单的一段代码,硬是报错,插入的数据也能显示出来

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的更多相关文章

  1. mysql报错com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException

    一.问题 运行java代码时报如下的错误: You have an error in your SQL syntax;Cause:com.mysql.jdbc.exceptions.jdbc4.MyS ...

  2. hibernate 报错com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException

    解释:JavaBean的主键类型只能是int类型,因为在映射关系配置是自动增长的,String类型是不能自动增长的,所以会报错.

  3. 求助:springboot调用存储过程并使用了pagehelper分页时报错com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException

    存储过程如下: dao层的sql Controller层调用: html页面 没有使用pagehelper分页之前,可以正常使用 使用了pagehelper之后就报错 ### Error queryi ...

  4. jeecg启动报错“com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Could not create connection to database server.”的解决办法

    在运行"maven build"-->"tomcat:run"之后,报如下错误: com.mysql.jdbc.exceptions.jdbc4.MySQ ...

  5. mybatis采坑之Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown column '?&#176;?&#233;?“&#233;?“' in 'field list'

    最后找到问题: 符号问题 修改之后正常

  6. [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 ...

  7. 【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 ...

  8. mybatis批量更新报错

    批量更新sql <update id="updateAutoAppraiseInfo" parameterType="Object"> <fo ...

  9. 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 ...

随机推荐

  1. codeforces 17D Notepad

    codeforces 17D Notepad 题意 题解 TBD 更新模板(phi.欧拉降幂) 代码 #include<bits/stdc++.h> using namespace std ...

  2. APP分析之海豚睡眠

    APP分析之海豚睡眠 产品:海豚睡眠 引文 由于笔者暑假经常晚睡,导致在习惯性失眠.长时间睡眠不足,导致头脑反应迟钝,还整日无精打采,不知所措.一个偶然的机会,在一个燥热的夜晚,眼看又是一个不眠之夜, ...

  3. 026.3 网络编程 TCP聊天

    分为客户端和服务端,分别进行收发操作##########################################################################客户端:###思 ...

  4. linux增加自己的可执行目录 $PATH

    Linux中有三种方法可以添加用户的路径到系统路径PATH, 以添加 /etc/apache/bin 为例: 方法一: 直接在命令行中输入: #PATH=$PATH:/etc/apache/bin 这 ...

  5. Linux无法识别Broadcom 802.11abgn无线网卡

    折腾了好久,都无法解决 索性后来直接使用的usb外置网卡,勉强能用(使用极其不便) 最后使尽浑身解数,冲着萤火般的希望,好在没有放弃 正解就是下面这   完成重启即可 sudo cp /sys/fir ...

  6. 关于vmware workstation10常见问题

    简单的说明:win7和win10的解决办法都是这个,都可以用这个解决. 这是一个共性的问题. 出现这个问题的原因是: a.要么是系统更新没有及时正确的关闭虚拟机导致的; b.没有及时将虚拟机手动关闭再 ...

  7. 细数用anaconda安装mayavi时出现的各种问题

    这段时间需要利用mayavi做科学数据的处理,因此需要利用到mayavi库,但是官网上面的指示说:如果安装了anaconda,其中自带各种科学库,但是实践中,并没有发现mayavi. 官方网站导航:m ...

  8. java 工作流项目源码 SSM 框架 Activiti-master springmvc 集成web在线流程设计器

    即时通讯:支持好友,群组,发图片.文件,消息声音提醒,离线消息,保留聊天记录 (即时聊天功能支持手机端,详情下面有截图) 工作流模块---------------------------------- ...

  9. HTML5基础知识总结(一)

    新增的标签和属性 1.结构标签 article section aside nav header footer hgroup figure address 2.媒体标签 video audio emb ...

  10. PHP原生开发的各大音乐平台API接口

    支持以下音乐平台 网易云音乐 QQ音乐 酷狗音乐 酷我音乐 虾米音乐 百度音乐 一听音乐 咪咕音乐 荔枝FM 蜻蜓FM 喜马拉雅FM 全民K歌 5sing原创 5sing翻唱 若是数据获取失败 方案一 ...