MySQL数据库:
<update id="writeOff" parameterType="Object"> <if test="list != null and list.size() > 0 "> <foreach collection="list" item="l" open="" close="" separator=";"> update sfb_pro_pay pp set pp.paycapital_balance = pp.paycapital_balance - #{l.write_off}, pp.status = #{l.status} where pp.pay_id = #{l.pay_id} </foreach> </if> </update>注意:MySQL数据需要dbc连接后加一个属性 &allowMultiQueries=true
例如:jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=gbk&
zeroDateTimeBehavior=convertToNull&allowMultiQueries=true
2017-04-13日更新:
上一次遇到这个问题时,没有把错误的日志信息给贴出来。
今天在执行批量删除的操作时,同样报错了。错误信息如下:
但是把sql语句拿出来到数据库客户端执行是没有问题的。org.springframework.jdbc.BadSqlGrammarException: ### Error updating database. Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: #42000 ### The error may involve defaultParameterMap ### The error occurred while setting parameters解决方案是同样是在jdbc连接后增加&allowMultiQueries=true这个属性。
本文介绍了一种在MySQL中执行批量更新操作的方法,并解决了在Spring框架下遇到的BadSqlGrammarException异常。通过调整JDBC连接字符串,加入允许多查询参数,确保了批量更新SQL语句的正确执行。
2974

被折叠的 条评论
为什么被折叠?



