How to do it...

We are going to demonstrate both bulk processing and batch processing. In order to accomplish it, let's follow these steps:

  1. An example of bulk processing is a single INSERT statement with multiple VALUES clauses:
INSERT into <table_name> (column1, column2, ...) VALUES                          ( value1,  value2, ...),                         ( value1,  value2, ...),                          ...                         ( value1,  value2, ...)

The code that constructs such a statement looks as follows:

int n = 100000;  //number of records to insertStringBuilder sb =  new StringBuilder("insert into person (name,age) values ");for(int i = 0; i < n; i++){   sb.append("(")     .append("'Name").append(String.valueOf(i)).append("',")     .append(String.valueOf((int)(Math.random() * 100)))     .append(")");   if(i < n - 1) {        sb.append(",");   }}

Get Java 11 Cookbook now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.