Skip to content
Ameen Abozaid
Planned lessonJNR-025-L05

Demo: batch import and timing comparison

  • Lesson 5 of 5
  • Junior
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

  1. Create the product table with schema.sql in local PostgreSQL.
  2. Read a 10,000-line CSV into a list of records.
  3. Insert row by row with auto-commit on; time it with System.nanoTime().
  4. Planned mistake: open a new DriverManager connection inside the loop; show how slow it gets, then switch to a pooled DataSource.
  5. Rewrite with addBatch/executeBatch in chunks of 500 and one commit per chunk; time again.
  6. Compare the two numbers and confirm all rows arrived with select count(*).

Practice

Apply this lesson with the module's lab, exercises and quiz.

Lab and exercises Quiz

Marking a lesson complete is optional and you can undo it any time. Your progress stays in this browser.

Type to search levels, phases, modules and lessons.