Class SQLErrorCodeSQLExceptionTranslator

All Implemented Interfaces:

public class SQLErrorCodeSQLExceptionTranslator extends AbstractFallbackSQLExceptionTranslator
Implementation of SQLExceptionTranslator that analyzes vendor-specific error codes. More precise than an implementation based on SQL state, but heavily vendor-specific.

This class applies the following matching rules:

  • Try custom translation implemented by any subclass. Note that this class is concrete and is typically used itself, in which case this rule doesn't apply.
  • Apply error code matching. Error codes are obtained from the SQLErrorCodesFactory by default. This factory loads a "sql-error-codes.xml" file from the class path, defining error code mappings for database names from database meta-data.
  • Fallback to a fallback translator. SQLStateSQLExceptionTranslator is the default fallback translator, analyzing the exception's SQL state only. Since Java 6 which introduces its own SQLException subclass hierarchy, we use SQLExceptionSubclassTranslator by default, which in turns falls back to Spring's own SQL state translation when not encountering specific subclasses.

The configuration file named "sql-error-codes.xml" is by default read from this package. It can be overridden through a file of the same name in the root of the class path (e.g. in the "/WEB-INF/classes" directory), as long as the Spring JDBC package is loaded from the same ClassLoader.

Rod Johnson, Thomas Risberg, Juergen Hoeller, Sam Brannen
See Also:
  • Constructor Details

    • SQLErrorCodeSQLExceptionTranslator

      public SQLErrorCodeSQLExceptionTranslator()
      Constructor for use as a JavaBean. The SqlErrorCodes or DataSource property must be set.
    • SQLErrorCodeSQLExceptionTranslator

      public SQLErrorCodeSQLExceptionTranslator(DataSource dataSource)
      Create an SQL error code translator for the given DataSource. Invoking this constructor will cause a Connection to be obtained from the DataSource to get the meta-data.
      dataSource - the DataSource to use to find meta-data and establish which error codes are usable
      See Also:
    • SQLErrorCodeSQLExceptionTranslator

      public SQLErrorCodeSQLExceptionTranslator(String dbName)
      Create an SQL error code translator for the given database product name. Invoking this constructor will avoid obtaining a Connection from the DataSource to get the meta-data.
      dbName - the database product name that identifies the error codes entry
      See Also:
    • SQLErrorCodeSQLExceptionTranslator

      public SQLErrorCodeSQLExceptionTranslator(SQLErrorCodes sec)
      Create an SQLErrorCode translator given these error codes. Does not require a database meta-data lookup to be performed using a connection.
      sec - error codes
  • Method Details