JavaRanch Home    
This page:         last edited 02 August 2013         What's Changed?         Edit

Sql Inserting Many Records   

Avoid inserting lots of records one by one

JDBC knows batching, and you should use it. Do not INSERT thousands of records one by one, re-creating a new PreparedStatement every time. If all of your records go to the same table, create a batch INSERT statement with a single SQL statement and multiple bind value sets. Depending on your database and database configuration, you may need to commit after a certain amount of inserted records, in order to keep the UNDO log slim.

The Cure:

Always batch-insert large sets of data.



JavaRanchContact us — Copyright © 1998-2014 Paul Wheaton