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

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. spark-submit提交参数设置

    /apps/app/spark-1.6.1-bin-hadoop2.6/bin/spark-submit --class com.zdhy.zoc2.sparksql.core.JavaSparkSq ...

  2. 【收集】Python 微优化

    1. 第二种方式可以节省寻找result的append属性的时间, 但会降低代码可读性和可维护性 # The way we're used to seeing it: result.append(&q ...

  3. 新手学Linux:在VMware14中安装CentOS7详细教程

    VMware Workstation14安装CentOS7.0 详情教程 1.准备工作 a)下载VMware workstation14 b)下载CentOS7 c)下载SSH Secure Shel ...

  4. Result工具类

    使用ajax请求访问时,可以用此工具类作为返回对象,也方便统一代码规范 package com.ujia.entity; import java.io.Serializable; public cla ...

  5. ubuntu下以16进制形式查看class文件、反编译class文件

    参考:https://blog.csdn.net/xyh930929/article/details/83860464 1.vim HelloWorld.class 2.输入英文状态下的冒号:,然后输 ...

  6. 1415. [NOI2005]聪聪和可可【记忆化搜索DP】

    Description Input 数据的第1行为两个整数N和E,以空格分隔,分别表示森林中的景点数和连接相邻景点的路的条数. 第2行包含两个整数C和M,以空格分隔,分别表示初始时聪聪和可可所在的景点 ...

  7. mysql 数据库数据迁移 The user specified as a definer ('root'@'%') does not exist 解决方法

    从一个数据库数据迁移到本地localhost 程序在调用到数据库的视图时报错,直接在数据库中打开视图时也报错,类似: mysql 1449 : The user specified as a defi ...

  8. Spring Boot中使用EhCache实现缓存支持

     SpringBoot提供数据缓存功能的支持,提供了一系列的自动化配置,使我们可以非常方便的使用缓存.,相信非常多人已经用过cache了.因为数据库的IO瓶颈.一般情况下我们都会引入非常多的缓存策略, ...

  9. springmvc IDEA

    回顾Java平台上Web开发历程来看,从Servlet出现开始,到JSP繁盛一时,然后是Servlet+JSP时代,最后演化为现在Web开发框架盛行的时代.一般接触到一个新的Web框架,都会想问这个框 ...

  10. django自带的登录验证功能

    django自带的验证机制 from django.shortcuts import render, redirect from django.contrib.auth import authenti ...