經過MyBatis框架,對Mysql數據庫作批量更新,對於的Mapper.xml配置:java
<update id="updateTestcaseNodeBatch" parameterType="List">
<foreach collection="list" item="nodeVO" separator=";">
UPDATE testcase_node
<set>
name=#{nodeVO.name},
version=#{nodeVO.version},
description=#{nodeVO.description},
last_modify_user=#{nodeVO.createUser},
last_modify_time=#{nodeVO.createTime}
</set>
<where>
object_id=#{nodeVO.objectId} AND root_id=#{nodeVO.rootId}
</where>
</foreach>
</update>
複製代碼
異常信息:node
### The error may involve com.hirain.testmanagement.mapper.TestcaseNodeMapper.updateTestcaseNodeBatch-Inline
### The error occurred while setting parameters
### SQL: UPDATE testcase_node SET name=?, version=?, description=?, last_modify_user=?, last_modify_time=? WHERE object_id=? AND root_id=? ; UPDATE testcase_node SET name=?, version=?, description=?, last_modify_user=?, last_modify_time=? WHERE object_id=? AND root_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 testcase_node
SET name='Türstatus',
version=4,
' at line 8 ; 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 testcase_node
SET name='Türstatus',
version=4,
' at line 8 at org.springframework.jdbc.support.SQLErrorCodeSQLExceptionTranslator.doTranslate(SQLErrorCodeSQLExceptionTranslator.java:233) 複製代碼
最終結果是 由於配置的 mysql jdbc連接字符串 默認不支持一次性執行多個sql語句
;可是在咱們的 update map中須要執行多個 update語句。最後加上參數 "allowMultiQueries" 設置爲true 以下:mysql
<property name="jdbcUrl" value="jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=utf-8&allowMultiQueries=true" />
複製代碼
問題解決!關鍵是解決問題的思路,由易到難,有外到內,確保最基本的配置不出問題。spring