We are going to demonstrate both bulk processing and batch processing. In order to accomplish it, let's follow these steps:
- 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(","); }}