org.springframework.jdbc.support
Class SQLErrorCodeSQLExceptionTranslator


public class SQLErrorCodeSQLExceptionTranslator
implements SQLExceptionTranslator

Implementation of SQLExceptionTranslator that uses specific vendor codes. More precise than SQLState implementation, but vendor specific.

The JdbcTemplate class enables error handling to be parameterized without making application's dependent on a particular RDBMS.

This class applies the following matching rules:

Author:
Rod Johnson, Thomas Risberg
Version: $Id: SQLErrorCodeSQLExceptionTranslator.java,v 1.1 2003/12/05 17:03:14 jhoeller Exp $
See Also: SQLErrorCodesFactory

Constructor Summary
SQLErrorCodeSQLExceptionTranslator()
          Constructor for use as a JavaBean.
SQLErrorCodeSQLExceptionTranslator(SQLErrorCodes sec)
          Create a SQLErrorCode translator given these error codes.
SQLErrorCodeSQLExceptionTranslator(DataSource ds)
          Create a SQLErrorCode translator for the given DataSource.

Method Summary
 voidsetDataSource(DataSource ds)
          Set the DataSource.
 voidsetFallbackTranslator(SQLExceptionTranslator fallback)
          Override the default SQLState fallback translator
 voidsetSqlErrorCodes(SQLErrorCodes sec)
          Set custom error codes to be used for translation
 DataAccessExceptiontranslate(String task, String sql, SQLException sqlex)
           

Constructor Detail

SQLErrorCodeSQLExceptionTranslator

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

SQLErrorCodeSQLExceptionTranslator

public SQLErrorCodeSQLExceptionTranslator(SQLErrorCodes sec)
Create a SQLErrorCode translator given these error codes. Does not require a database metadata lookup to be performed using a connection.
Parameters:
sec - error codes

SQLErrorCodeSQLExceptionTranslator

public SQLErrorCodeSQLExceptionTranslator(DataSource ds)
Create a SQLErrorCode translator for the given DataSource. Invoking this constructor will cause a connection to be obtained from the DataSource to get the metadata
Parameters:
ds - DataSource to use to find metadata and establish which error codes are usable
Method Detail

setDataSource

public void setDataSource(DataSource ds)
Set the DataSource. Setting this property will cause a connection to be obtained from the DataSource to get the metadata
Parameters:
ds - DataSource to use to find metadata and establish which error codes are usable

setFallbackTranslator

public void setFallbackTranslator(SQLExceptionTranslator fallback)
Override the default SQLState fallback translator
Parameters:
fallback - custom fallback exception translator to use if error code translation fails

setSqlErrorCodes

public void setSqlErrorCodes(SQLErrorCodes sec)
Set custom error codes to be used for translation
Parameters:
sec - custom error codes to use

translate

public DataAccessException translate(String task, String sql, SQLException sqlex)
See Also:
SQLExceptionTranslator.translate(java.lang.String,java.lang.String,java.sql.SQLException)

Association Links

to Class org.springframework.jdbc.support.SQLErrorCodes

Error codes available to subclasses

to Class org.springframework.jdbc.support.SQLExceptionTranslator

Fallback translator to use if SQLError code matching doesn't work