Class JdbcExceptionHelper

java.lang.Object
org.hibernate.jdbc.spi.JdbcExceptionHelper

@SPI(USE) public final class JdbcExceptionHelper extends Object

Inspects a JDBC exception chain for vendor error information.

JDBC drivers sometimes report the useful error code or SQL state on a nested exception reached through SQLException.getNextException(). These operations return the first usable value in that JDBC exception chain. They do not inspect the general Java cause chain.

Since:
8.0
  • Method Details

    • extractErrorCode

      @SPI(USE) public static int extractErrorCode(SQLException sqlException)
      Finds the first nonzero vendor error code in the JDBC exception chain.
      Parameters:
      sqlException - the first exception in the chain
      Returns:
      the first nonzero error code, or zero when every error code is zero
      Since:
      8.0
    • extractSqlState

      @SPI(USE) @Nullable public static String extractSqlState(SQLException sqlException)
      Finds the first non-null SQL state in the JDBC exception chain.
      Parameters:
      sqlException - the first exception in the chain
      Returns:
      the first SQL state, or null when none is available
      Since:
      8.0
    • extractSqlStateClassCode

      @SPI(USE) @Nullable public static String extractSqlStateClassCode(SQLException sqlException)
      Finds the first SQL state and returns its two-character class code.
      Parameters:
      sqlException - the first exception in the chain
      Returns:
      the SQL-state class code, or null when no state is available
      Since:
      8.0
    • determineSqlStateClassCode

      @SPI(USE) @Nullable public static String determineSqlStateClassCode(@Nullable String sqlState)

      Returns the two-character class code of a SQL state.

      A null or shorter value is returned unchanged.

      Parameters:
      sqlState - a SQL state, or null
      Returns:
      its class code, or the unchanged null or short value
      Since:
      8.0