mysql批量更新 bad SQL grammar [] 错误

版权声明:可以转载,说明来源。 https://blog.csdn.net/weixin_42776979/article/details/81671389

错误代码如下:

### The error may involve org.wz.dao.LiaoningComInfoTyMapper.updateBatchSyncPhoneAndEmail-Inline
### The error occurred while setting parameters
### SQL: update liaoning_com_info_ty          SET com_phone = ?          where com_name = ?       ;       update liaoning_com_info_ty          SET com_phone = ?,                              com_email = ?          where com_name = ?
### 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 liaoning_com_info_ty
         SET com_phone = '13999620408,13565741070,13' at line 5
; 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 liaoning_com_info_ty
         SET com_phone = '13999620408,13565741070,13' at line 5

代码如下:

 <!-- 批量同步手机号码 和邮箱账号 -->
  <update id="updateBatchSyncPhoneAndEmail" parameterType="java.util.List">
     <foreach collection="list" item="item" index="index" open="" close="" separator=";">
    	update liaoning_com_info_ty
        <set> 
	        <if test="item.comPhone != null and item.comPhone !='' " >
        	com_phone = #{item.comPhone},
	        </if>
	        <if test="item.comEmail != null and item.comEmail != '' " >
        	com_email = #{item.comEmail}
        	</if>
        </set>
        where com_name = #{item.comName}
     </foreach>
  </update>

只有一条的时候可以执行,两条以上就会报错。

纠结半天,么有发现问题。最后终于明白了,allowMultiQueries=true  需要这个参数才能执行多条sql,默认是一条。

jdbcUrl=jdbc:mysql://192.168.1.203:3306/shiro?useUnicode=true&characterEncoding=utf8&allowMultiQueries=true

猜你喜欢

转载自blog.csdn.net/weixin_42776979/article/details/81671389