Demo: batch import and timing comparison
On This Lesson 3 topics
This lesson is planned. The outline below lists the topics it will cover. The full lesson has not been published yet.
In this lesson
measure row-by-row against batched inserts; prepares JNR-025-LAB1.
Draft outline details
Step by step
- Create the
producttable withschema.sqlin local PostgreSQL. - Read a 10,000-line CSV into a list of records.
- Insert row by row with auto-commit on; time it with
System.nanoTime(). - Planned mistake: open a new
DriverManagerconnection inside the loop; show how slow it gets, then switch to a pooledDataSource. - Rewrite with
addBatch/executeBatchin chunks of 500 and one commit per chunk; time again. - Compare the two numbers and confirm all rows arrived with
select count(*).
Practice
Apply this lesson with the module's lab, exercises and quiz.
Marking a lesson complete is optional and you can undo it any time. Your progress stays in this browser.