oracle批量入库解决方案
2021/11/5 2:10:12
本文主要是介绍oracle批量入库解决方案,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
思路:jdbcTemplate
核心代码两个:
1、batchInserPrepard入库
@Autowired
private JdbcTemplate jdbcTemplate;
public int batchInsertPrePared(List<MyOBject> list){
String sql="insert into T_MY_TABLE values(?,?,?,?)";
int[] insertCountArray = jdbcTemplate.batchUpdate(sql, new BatchPreparedStatementSetter() {
@Override
public void setValues(PreparedStatement ps, int i) throws SQLException {
ps.setString(1, list.get(i).getId());//主键
ps.setString(1, list.get(i).getColumnsOne());
ps.setString(1, list.get(i).getColumnsTwo());
ps.setString(1, list.get(i).getColumnsThree());
}
@Override
public int getBatchSize() {
return list.size();
}
});
int sumInsertedCount = 0;
for (int a : insertCountArray) {
sumInsertedCount += a;
}
return insertCountArray.length;
}
}
2、解析组装list对象方法
//解析代码(只列核心代码)
List<TMOBJECT> objectList = new ArrayList<TMOBJECT>(2000);//性能优化防止自东扩. 容,直接设置默认值
objectList.add(temp);
if (objectList.size() == 2000) {
int a = tMYObjectService.batchInsertPrePared(objectList);
sumInsertedCount += a;
logger.info("批次:" + objectList.size() + "入库完毕");
objectList.clear();
}
}
实现原理:使用batchInsertPrePared批量入库,每两千一批次,设置list的默认值大小,防止list自东扩容提高性能。batchInsertPrePared 执行完毕后,clear() list对象。核心代码如上所示。
这篇关于oracle批量入库解决方案的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-07-07Dify + TiDB Vector,快速构建你的AI Agent
- 2024-07-06有没有什么开源的py项目可以对图像进行分类-icode9专业技术文章分享
- 2024-07-05feign默认connecttimeout和readtimeout是多少-icode9专业技术文章分享
- 2024-07-05idea控制台,日志太多,导致部分想看得日志被刷走 搜不到-icode9专业技术文章分享
- 2024-07-05The server selected protocol version Tls10 is not accepted by client preferences [TLs12]-icode9专业技术文章分享
- 2024-07-05怎么清理项目缓存-icode9专业技术文章分享
- 2024-07-04安装 Eyoucms详细图文教程-icode9专业技术文章分享
- 2024-07-04ueditor 复制文章时,图片的链接是一个下载图片地址,该如何处理?-icode9专业技术文章分享
- 2024-07-04怎样判断host有没有对wordpress有缓存呢-icode9专业技术文章分享
- 2024-07-04具有编译功能的系统make后,无法ssh连接-icode9专业技术文章分享