批量更新sql语句
mysql批量更新badSQLgrammar[]错误
错误代码如下:
### 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 = ?,  ### Cause: ptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your My          SET com_phone = '139********,135********,13' at line 5
; bad SQL grammar []; nested exception ptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manu          SET com_phone = '139********,135********,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="itemPhone != null and itemPhone !='' " >
com_phone = #{itemPhone},
</if>
<if test="itemEmail != null and itemEmail != '' " >
com_email = #{itemEmail}
</if>
</set>
where com_name = #{itemName}
</foreach>
</update>
只有⼀条的时候可以执⾏,两条以上就会报错。
纠结半天,么有发现问题。最后终于明⽩了,allowMultiQueries=true  需要这个参数才能执⾏多条sql,默认是⼀条。
jdbcUrl=jdbc:mysql://192.168.1.203:3306/shiro?useUnicode=true&characterEncoding=utf8&allowMultiQueries=true