# Use Batch To Insert In Batches

__*rewriteBatchedStatements*__

+ Uses batch insertion to leverage TiDB concurrent processing
+ `addBatch()`and`executeBatch` API
+ `rewriteBatchedStatements`

```12
jdbc:mysql://<tidb_server>:<port>/<db_name>?~!@rewriteBatchedStatements=true@!~
```

------------------------------------------------------------
For batch insert updates, you can choose to use the AddBatch/ExecuteBatch API if you insert a large number of records. Multiple SQL inserts and update records are cached on the client side by means of AddBatch, and then sent to the database server at the time of ExecuteBatch.

1. Principle:
When SQL statement are executed through JDBC, the SQL statements for update and delete are sent to the database for execution one by one.
BUT! The processing speed of the database is fast, the single throughput is large, and the execution efficiency is extremely high. At this point, a "conflict" occurs, and the database processes quickly, but the execution of the statement sent to the database for execution is sent one by one, at an imaginable speed. Therefore, the extremely fast processing speed of the database in this case cannot be reflected. So, to resolve this "conflict", **addBatch () ** appeared! addBatch () loads a number of SQL statement together, and then sends them to the database for execution at once, that is, batch processing SQL data. As a result, the "conflict" was resolved and the implementation time was significantly shortened.

2. Settings:
For MySQL Connector/J implement, the default Batch only delays the SQL sending of AddBatch multiple times until ExecuteBatch is called, but the actual network send is still a single packet, which usually does not reduce the number of network interactions with the database server.

3. Conclusion:
If you want batch network delivery, you need to configure RewriteBatchedDelivered = true in the JDBC connection flag