Skip to content

Files

Latest commit

 

History

History

c_10_8_dealing_with_exceptions

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 

🧠 10.8 Dealing with Exceptions

  • We can catch and handle the SQL exception:
String url = "jdbc:derby:zoo";
try (Connection conn = DriverManager.getConnection(url);
     Statement stmt = conn.createStatement();
     ResultSet rs = stmt.executeQuery("SELECT bad FROM animal")) {
  while(rs.next())
    System.out.println(rs.getString(1));
} catch (SQLException e) {
  System.out.println(e.getMessage());
  System.out.println(e.getSQLState());
  System.out.println(e.getErrorCode());
}
  • This will print the following:
ERROR: column "bad" does not exist
  Position: 8
42703
0