// 批量插入,手动控制事务
SqlSession batchSqlSession = null;
try {
    batchSqlSession = sqlSessionTemplate.getSqlSessionFactory()
        .openSession(ExecutorType.BATCH, false);// 获取批量方式的sqlsession
    int batchCount = 1000;// 每批commit的个数
    int batchLastIndex = batchCount - 1;// 每批最后一个的下标
    for (int index = 0; index < saveList.size();) {
        if (batchLastIndex > saveList.size()) {
            batchLastIndex = saveList.size();
            batchSqlSession.insert(
                "com.jomoo.oms.baseData.mapper.CapaCityMapper.create2",
                saveList.subList(index, batchLastIndex));
            batchSqlSession.commit();
            break;// 数据插入完毕,退出循环
        } else {
            batchSqlSession.insert(
                "com.jomoo.oms.baseData.mapper.CapaCityMapper.create2",
                saveList.subList(index, batchLastIndex));
            batchSqlSession.commit();
            index = batchLastIndex;// 设置下一批下标
            batchLastIndex = index + (batchCount - 1);
        }
    }
} catch (Exception e) {
    throw new OptException(e.getMessage());
} finally {
    batchSqlSession.close();
}
<insert id="create2"  parameterType="com.jomoo.oms.baseData.model.CapaCityModel">
    <selectKey keyProperty="id" order="BEFORE" resultType="Long">
        select JOMOO_OMS.OMS_CAPACITY_S.NEXTVAL as id from dual
    </selectKey>

    insert into JOMOO_OMS.OMS_CAPACITY(<include refid="Base_Column_List"></include>) select JOMOO_OMS.OMS_CAPACITY_S.NEXTVAL, A.*
    from (
    <foreach collection="list" item="capacity" index="index" open="" close="" separator="union all">
        select
        #{capacity.factoryCode},
        #{capacity.factoryName},
        #{capacity.productSeriesCode},
        #{capacity.productSeries},
        #{capacity.materialCode},
        #{capacity.materialName},
        #{capacity.dateNumber},
        #{capacity.totalCapacity},
        #{capacity.leftCapacity},
        #{capacity.remark},
        #{capacity.registerId},
        #{capacity.createdByEmployee},
        #{capacity.createdByDept},
        #{capacity.enableFlag},
        sysdate
        from dual
    </foreach>
    ) A
</insert>

mybatis+oracle的批量插入的更多相关文章

  1. mybatis oracle mysql 批量插入时的坑爹问题--需谨记

    mybatis oracle mysql 批量插入一.oracle的批量插入方式insert into db(id, zgbh, shbzh) select '1', '2', '3' from du ...

  2. Oracle 存储过程批量插入数据

    oracle 存储过程批量插入大量数据 declare numCount number; userName varchar2(512); email varchar2(512); markCommen ...

  3. MyBatis 使用 foreach 批量插入

    MyBatis 使用 foreach 批量插入 参考博文 老司机学习MyBatis之动态SQL使用foreach在MySQL中批量插入 使用MyBatis一次性插入多条数据时候可以使用 <for ...

  4. Mybatis中实现oracle的批量插入、更新

    oracle 实现在Mybatis中批量插入,下面测试可以使用,在批量插入中不能使用insert 标签,只能使用select标签进行批量插入,否则会提示错误 ### Cause: java.sql.S ...

  5. mybatis使用序列批量插入数据

    mybatis只提供了单条数据的插入,要批量插入数据我们可以使用循环一条条的插入,但是这样做的效率太低下,每插入一条数据就需要提交一次,如果数据量几百上千甚至更多,插入性能往往不是我们能接受的,如下例 ...

  6. oracle+ibatis 批量插入-支持序列自增

    首先请先看我前面一篇帖子了解oracle批量插入的sql:[oracle 批量插入-支持序列自增] 我用的ibatis2.0,sqlMap文件引入的标签如下: <!DOCTYPE sqlMap ...

  7. Oracle中批量插入

    为了防止OracleConnection的重复打开和关闭,使用begin end:将sql语句包在里面,然后一次性执行提高插入的效率. 下面代码中要插入的数据在list集合中,如果list集合的cou ...

  8. Oracle/Mysql批量插入的sql,效率比较高

    1.oracle 批量插入: insert into tableName(col1,col2,col3...)    select 1,'第一行第一列值','第二列值' from dual union ...

  9. Mybatis与JDBC批量插入MySQL数据库性能测试及解决方案

    转自http://www.cnblogs.com/fnz0/p/5713102.html 不知道自己什么时候才有这种钻研精神- -. 1      背景 系统中需要批量生成单据数据到数据库表,所以采用 ...

随机推荐

  1. Codeforces 626 B. Cards (8VC Venture Cup 2016-Elimination Round)

      B. Cards   time limit per test 2 seconds memory limit per test 256 megabytes input standard input ...

  2. HTTP.SYS

    严格地说,HTTP.SYS已经不属于IIS 的范畴了,所以HTTP.SYS的配置信息也没有保存在IIS 的元数据库(Metabase) 中,而是定义在注册表中.HTTP.SYS 的注册表项的路径为HK ...

  3. CF 917A The Monster 【括号匹配】

    [链接]:CF Examples inputCopy ((?)) outputCopy 4 inputCopy ??()?? outputCopy 7 说明 For the first sample ...

  4. [Contest20180323]King

    跳蚤国王要召开第二届内阁会议,所以把所有跳蚤都召集到了会议室.所有跳蚤在会议室的圆桌前坐成了一个圈,从$1$到$n$标号,每人的面前都有一盏明灯. 就在会议就要开始的时候,国王突然发现,并不是所有的灯 ...

  5. 【计算几何】【凸包】bzoj2829 信用卡凸包

    http://hzwer.com/6330.html #include<cstdio> #include<cmath> #include<algorithm> us ...

  6. Exercise01_09

    public class S{ public static void main(String[] args){ double w=4.5; double h=7.9; double d; double ...

  7. java读写文件及保留指定位小数

    1)先上代码: public static void main(String[] args)throws IOException{ double[][] B=new double[1043][2102 ...

  8. 关于GIT的一些注意点

    往空仓库提交代码之前先将文档区的_gitignore放到项目根目录然后改名成.gitignore然后git add .gitignore以上的目的是忽略一些不应该提交GIT的文件,多人编辑工程的时候不 ...

  9. no such file or directory : 'users/shikx/xxx/xxx/Appirater.m'

    删除此处红色的.m文件即可

  10. 【spring mvc】spring mvc POST方式接收单个字符串参数,不加注解,接收到的值为null,加上@RequestBody,接收到{"uid":"品牌分类大”},加上@RequestParam报错 ---- GET方式接收单个参数的方法

    spring mvc POST方式 接收单个参数,不加任何注解,参数名对应,接收到的值为null spring mvc POST方式 接收单个参数,加上@RequestBody,接收到参数格式:{&q ...