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

Connected

Exercise

Sorting the data

CityBook Libraries' search feature works well, but users want to sort results by publication year in either ascending or descending order. You'll build the query dynamically to handle both sort directions.

The HikariSetup class is already configured for you.

Instructions

100 XP
  • Complete the query to sort the result by the publication_year.
  • Extend the query to sort in ascending or descending order depending on the ascending variable representing the user input.