Skip to content
Zsolt Herpai edited this page Aug 7, 2017 · 7 revisions

Batch insert and update queries

query.batch(sqlQuery)...

Creates a batch insert or update query that can be parameterized, customized and executed.

Parameters

Both positional and named parameters are supported. Parameters needs to be provided as Iterators - to support big data.

Stream<List<Object>> params = ...; // or Iterable/Iterator
query
	.batch("INSERT INTO CUSTOMER(NAME, ADDRESS) VALUES(?, ?)")
	.params(params)
	.run();

With named parameters:

Iterator<Map<String, Object>> params = ...;
query
	.batch("INSERT INTO CUSTOMER(NAME, ADDRESS) VALUES(:name, :address)")
	.namedParams(params)
	.run();

Batch size

There is no default batch size, which means insert/updates will be executed in a single batch. This may lead to high memory consumption with large sets of data. The batch size can be specified "globally" for FluentJdbc or per query:

query
   .batch("INSERT INTO CUSTOMER(NAME, ADDRESS) VALUES(:name, :address)")
   .namedParams(params)
   .batchSize(1000)
   .run();