try { // code that may throw SQLException } catch (SQLException e) { System.err.println("SQL error occurred: " + e.getMessage()); }
try { // code that may throw SQLException } catch (SQLException e) { if (e.getSQLState().equals("08001")) { // This is a recoverable error, retry the operation } else { // This is not recoverable, rethrow the exception or terminate the program } }
import java.util.logging.*; Logger logger = Logger.getLogger("MyApp"); try { // code that may throw SQLException } catch (SQLException e) { logger.log(Level.SEVERE, "An SQL error occurred", e); }The java.sql.SQLException class is part of the Java standard library and is included in the java.sql package.