mybatis執行批量更新batch update 的方法(oracle,mysql)


有時候oracle的最后一個sql少個分號,要在end前面加上分號
 
oracle和mysql數據庫的批量update在mybatis中配置不太一樣:
oracle數據庫:
<update id="batchUpdate" parameterType="java.util.List"> <foreach collection="list" item="item" index="index" open="begin" close="end;" separator=";"> update test <set> test=${item.test}+1 </set> where id = ${item.id} </foreach> </update>
mysql數據庫:
mysql數據庫采用一下寫法即可執行,但是數據庫連接必須配置:&allowMultiQueries=true
例如:jdbc:mysql://192.168.1.236:3306/test?useUnicode=true&amp;characterEncoding=UTF-8&allowMultiQueries=true
<update id="batchUpdate" parameterType="java.util.List"> <foreach collection="list" item="item" index="index" open="" close="" separator=";"> update test <set> test=${item.test}+1 </set> where id = ${item.id} </foreach> </update>


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM