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

Connected

Exercise

Connection management

Database connections are expensive resources that must be closed properly to avoid memory leaks. Java's try-with-resources syntax automatically closes connections, statements, and result sets when the block completes, even if errors occur.

Ensure CityBook Libraries' application manages resources safely.

Instructions

100 XP
  • Wrap resources in a try-with-resources block.
  • Add exception handling for database errors.