O'Reilly logo

Java 11 Cookbook by Mohamed Sanaulla, Nick Samoylov

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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(",");   }}

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required