mybatis+oracle的批量插入
2024-10-20 11:29:09
// 批量插入,手动控制事务
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>
最新文章
- PHP设计模式(七)适配器模式(Adapter For PHP)
- Codeforces Round #366 (Div. 2)
- Selenium Webdriver元素定位的八种常用方式
- oracle数据库表空间文件收缩实例
- mp3 切割
- Web API接口 安全验证
- C++学习笔记-1-自增和自减运算符
- android入门——UI(6)——ViewPager+Menu+PopupWindow
- python文件操作_对文件进行复制拷贝_代码实现
- java日期详解
- openstack第三章:nova
- 不使用接口的 limit 控制分页的容量
- Linux-01初级学习
- Python3学习笔记33-正则表达式
- Windows 10 Install rabbitmq-server-3.6.9
- Java泛型的一些限制
- window.location属性用法及解决一个window.location.search为什么为空的问题
- spark本地环境的搭建到运行第一个spark程序
- Jquery js框架使用
- redis系列:基于redis的分布式锁
热门文章
- 【互动问答分享】第8期决胜云计算大数据时代Spark亚太研究院公益大讲堂
- 获取apk的appPackage和appActivity方法
- (1) Flutter android studio安装
- Maven学习笔记3
- 洛谷——P2371 EXCEEDED WARNING C(50)
- Proxy(2016山东省省赛C)(最短路)(spfa)
- 9、Flask实战第9天:类视图
- 【mybatis】idea中 mybatis的mapper类去找对应的mapper.xml中的方法,使用插件mybatis-plugin
- [干货]2017已来,最全面试总结——这些Android面试题你一定需要
- unity3d开发app的框架