oracel和db2 mybatis批量更新

本文详细介绍使用MyBatis在不同数据库(Oracle、DB2AS400、DB2AIX)环境下执行批量更新操作的方法,包括mapper.xml配置与DAO接口实现,适合于需要进行高效数据更新的开发人员。

网上有很多关于mybatis批量更新的例子,但基本都是针对mysql或oracle的,针对db2的少之又少;

一、oracle+mybatis执行批量更新:

mapper.xml:

<update id="doupdateBatchResUpStatusById" parameterType="java.util.List">
        <foreach collection="list" item="item" index="index" open="begin" close=";end;" separator=";">
        UPDATE EPJT_SBSJ_DBXX 
        <set>
         RES_UP_STATUS=3,
         res_local_err_desc=#{item.resLocalErrDesc},
         res_local_err_code=#{item.resLocalErrCode}, 
         RES_UP_TIME = #{item.resUpTime} 
        </set>
        where RES_UP_STATUS=1 AND SBSJID = #{item.sbsjid}
        </foreach>      

    </update>

dao接口:
    public int doupdateBatchResUpStatusById(List<T> listObject)throws Exception;

二、db2as400+mybatis执行批量更新:

mapper.xml:

<update id="doupdateBatchResUpStatusById" parameterType="java.util.List">
        <foreach collection="list" item="item" index="index"  open="BEGIN" close=";END" separator=";" >
        UPDATE EPJT_SBSJ_DBXX 
        <set>
         RES_UP_STATUS=3,
         <if test="item.resLocalErrDesc != null ">
         res_local_err_desc='${item.resLocalErrDesc}',
         </if>
         <if test="item.resLocalErrCode != null ">
         res_local_err_code='${item.resLocalErrCode}',
         </if>
         RES_UP_TIME = current  timestamp
        </set>
        where RES_UP_STATUS=1 AND SBSJID = ${item.sbsjid}
        </foreach>      

    </update>

dao接口:

public int doupdateBatchResUpStatusById(List<T> listObject)throws Exception;

三、db2aix+mybatis执行批量更新:

mapper.xml:

<update id="doupdateBatchResUpStatusById" parameterType="java.util.List">
        <foreach collection="list" item="item" index="index"  open="BEGIN" close=";END" separator=";" >
        UPDATE EPJT_SBSJ_DBXX 
        <set>
         RES_UP_STATUS=3,
         res_local_err_desc=#{item.resLocalErrDesc,jdbcType=VARCHAR},
         res_local_err_code=#{item.resLocalErrCode,jdbcType=VARCHAR},
         RES_UP_TIME = #{item.resUpTime,jdbcType=DATE}  
        </set>
        where RES_UP_STATUS=1 AND SBSJID = #{item.sbsjid,jdbcType=INTEGER}
        </foreach>      

    </update>

dao接口:

public int doupdateBatchResUpStatusById(List<T> listObject)throws Exception;
————————————————
版权声明:本文为CSDN博主「zhengzixiang666」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/zhengzixiang666/article/details/89472734

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值