You should be able to simply add the appropriate catch (Exception e) { }
clause. If you need to do special handling for a specific one, or you can simply catch Exception
, if you need it much broader.
try (Statement stmt = con.createStatement()) {
ResultSet rs = stmt.executeQuery(query);
while (rs.next()) {
String coffeeName = rs.getString("COF_NAME");
int supplierID = rs.getInt("SUP_ID");
float price = rs.getFloat("PRICE");
System.out.println(coffeeName + ", " + supplierID + ", " +
price + ", " + sales + ", " + total);
}
} catch (Exception e) {
System.out.println("Exception while trying to through the queries. ", e);
}
Since it's Java 7, you can actually put multiple exceptions per catch clause, or you can simply catch the outermost exception you want.