jdbctemplate 批量插入
public void batchImport(List<Map<String, Object>> list) {
String sql = "insert into table1(field1, field2) values(?,?)";
int[] types = new int[2];
types[0] = Types.VARCHAR;
types[1] = Types.NUMERIC;
List<Object[]> paramsArr = new ArrayList<Object[]>();
for (int i = 0; i < list.size(); i++) {
Map<String, Object> item = list.get(i);
Object[] params = new Object[2];
params[0] = item.get("param0");
params[1] = item.get("param1");
paramsArr.add(params);
if (i == tables.size() - 1 || (i != 0 && i % 100 == 0)) {//每100条执行一次
jdbcTemplate.batchUpdate(sql, paramsArr, types);
paramsArr = new ArrayList<Object[]>();
}
}
}
jdbctemplate 批量插入的更多相关文章
- spring JdbcTemplate批量插入以及单个插入时获取id
1. 批量更新插入 jdbcTemplate.batchUpdate(String sql, List<Object[]> batchArgs) Object[]数组的长度为每条记录的参数 ...
- JdbcTemplate批量插入数据
运行环境:SpringBoot,注入JdbcTemplate @Autowired private JdbcTemplate jdbcTemplate; 1.单表批量插入数据 @Test public ...
- jdbcTemplate批量插入处理数据
最近有个需求,就是批量处理数据,但是并发量应该很大,当时第一时间想到得是mybatis的foreach去处理,但是后来通过查资料发现,相对有spring 的jdbcTemplate处理速度,mybat ...
- jdbcTemplate批量插入(添加)
public void addSubscibe(List<PermedipUserSubscribeVo> list) { final List<PermedipUserSubscr ...
- Spring利用JDBCTemplate实现批量插入和返回id
1.先介绍一下java.sql.Connection接口提供的三个在执行插入语句后可取的自动生成的主键的方法: //第一个是 PreparedStatement prepareStatement(St ...
- 【JDBC】使用Spring提供的JDBCTemplate通过Statement向MySql数据库插入千万条数据,耗时4m55s,使用insert语句批量插入方式二
这回依然是使用 insert批量插入这种方式 insert into emp(name,age,cdate) values ('A' , 20, '2019-10-13 00:00:00'), ('B ...
- JDBC批量插入数据效率分析
对于需要批量插入数据库操作JDBC有多重方式,本利从三个角度对Statement和PreparedStatement两种执行方式进行分析,总结较优的方案. 当前实现由如下条件: 执行数据库:Mysql ...
- spring data jpa开启批量插入、批量更新
spring data jpa开启批量插入.批量更新 原文链接:https://www.cnblogs.com/blog5277/p/10661096.html 原文作者:博客园--曲高终和寡 *** ...
- jdbc批量插入数据
//插入很多书(批量插入用法) public void insertBooks(List<Book> book) { final List<Book> tempBook=b ...
随机推荐
- 《汇编语言 基于x86处理器》第十三章高级语言接口部分的代码 part 2
▶ 书中第十三章的程序,主要讲了汇编语言和 C/++ 相互调用的方法 ● 代码,汇编中调用 C++ 函数 ; subr.asm INCLUDE Irvine32.inc askForInteger P ...
- add_polygon_to_map
var poly = new esri.geometry.Polygon({ "rings": [ [[117.008726, 30.931672], [117.009635, 3 ...
- springBoot整合MongoDB(单机)
依赖: <!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-data-mon ...
- Linux 设置IP地址,并能连接外网
1,如果是 centos6,请修改 vi /etc/sysconfig/network-scripts/ifcfg-eth0 2,如果是 centos7,请修改 => vi /etc/sysc ...
- centos7.5安装golang
1.下载 [root@localhost bin]#wget https://dl.google.com/go/go1.10.2.linux-amd64.tar.gz [root@localhost ...
- JS 原型链 prototypt 和隐式原型 _proto_
prototype(原型) : 对象的一个属性,此属性使您有能力向对象添加属性和方法,当访问对象不存在属性是会自动到 prototype 中找 _proto_(隐式原型): 此对象构造函数(类)的原 ...
- FDQuery多表更新生成sql语句的问题
query.sql='select a,b,c,d,e from a,b,c where ....'; 来源3个表, 设计时添加字段列表,每个字段有Origin属性 分别是a.a,b.b,c.c格式 ...
- day31-软件开发规范
一.为什么要规范软件开发? 1.1 为什么要有规范软件开发 你现在包括之前写的一些程序,所谓的'项目',都是在一个py文件下完成的,代码量撑死也就几百行,你认为没问题,挺好.但是真正的后端开发的项目, ...
- hive,分桶,内外部表,分区
简单的word-count操作: [root@master test-map]# head -10 The_Man_of_Property.txt #先看看数据Preface“The Forsy ...
- WDA-1-环境配置
1.Internet Communication Manager 确认ICM中提供的HTTP/HTTPS运行正常. Tcode: SMICM -> Display service. ICM在SA ...