1. Learn
  2. /
  3. Courses
  4. /
  5. Querying a PostgreSQL Database in Java

Connected

Exercise

Book Club Saturdays

The Metropolitan Public Library hosts "Book Club Saturdays," a wildly popular event where 30-40 members arrive at 10 AM to check out their monthly selections. The current system processes each loan individually with auto-commit enabled, creating two critical problems:

  1. Data inconsistency: Last month, the system crashed while processing a member's four-book checkout. Two books were recorded as loaned, but the other two weren't, causing inventory discrepancies and frustrated patrons.
  2. Performance bottleneck: Processing each loan as a separate database transaction takes 15-20 minutes, creating long queues and unhappy library staff.

Your mission is to implement batch processing with transaction control.

Instructions

100 XP
  • Set autoCommit to false to enable manual transaction control in line 32.
  • Add multiple loans to the batch in line 43.
  • Commit the transaction if all operations are successful in line 49.