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

Connected

Exercise

Books report

CityBook Libraries wants to generate a catalog report showing their book collection. You'll use HikariCP connection pooling to fetch data efficiently from the PostgreSQL database.

The query selects book_id, title, and publication_year from the books table. Put together everything you've learned: get a pooled connection, create a statement, execute the query, and extract the results. The HikariSetup class and HikariDataSource are already imported for you.

Instructions

100 XP
  • Get a connection from the data source using getConnection().
  • Create a statement with createStatement().
  • Execute the query using executeQuery(query).
  • Use the correct getter methods for book_id and title.