Jdbcbatchitemwriterbuilder vs Org. Springframework. Jdbc. Core. jdbcTemplate. batchUpdate

I understand jdbcTemplate.batchUpdate is used for sending several records to data base in one communication. Lets say i have 1000 records to be updated, instead of 1000 communications from Application to database, the Application will send 1000 records in request.

Coming to JdbcBatchItemWriterBuilder its combination of Tasks in a job.

My question is, if there is 1000 records to be processed(INSERT statements) via JdbcBatchItemWriterBuilder, all INSERTS executed in one go? or one after one?

If one after one, connecting to database 1000 times using JdbcBatchItemWriterBuilder causes perf issues? hows that handled?

i would like to understand if Spring batch performs better than running 1000 INSERT staments using jdbcTemplate.update ?

1 Answer

The JdbcBatchItemWriter uses java.sql.PreparedStatement#addBatch and java.sql.Statement#executeBatch internally (See ), so there will be a single batch insert for all items of the chunk.

Moreover, this will be executed in a single transaction as described in the Chunk-oriented Processing section of the reference documentation.

3

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

David Miller

David Miller

Executive Financial & Market Analyst

David Miller brings 15 years of experience in global economics, personal finance strategy, and market dynamics. He specializes in turning complex economic trends into actionable insights for everyday readers.

Share this article
Twitter Facebook Pinterest