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

Connected

Exercise

Handling Database Exceptions

Database operations can fail for several reasons: a table may not exist, a column name may be misspelled, or the connection may drop. JDBC uses SQLException to capture these errors, providing details like error messages and SQL state codes.

The query in this exercise has an intentional typo (boks instead of books).

Instructions

100 XP
  • Catch the exception when the query fails.
  • Print the error message and SQLState from the exception.