Top Description Methods
org.springframework.jdbc.support

public Interface SQLExceptionTranslator

Known Direct Implementers
org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator
Annotations
@FunctionalInterface
Imports
java.sql.SQLException, org.springframework.dao.DataAccessException, org.springframework.lang.Nullable

Strategy interface for translating between SQLExceptions and Spring's data access strategy-agnostic DataAccessException hierarchy.

Implementations can be generic (for example, using SQLState codes for JDBC) or wholly proprietary (for example, using Oracle error codes) for greater precision.

Authors
Rod Johnson, Juergen Hoeller
See Also
org.springframework.dao.DataAccessException

Method Summary

Modifier and TypeMethod and Description
public DataAccessException

Returns:

the DataAccessException wrapping the SQLException, or null if no specific translation could be applied
translate
(String
readable text describing the task being attempted
task
,
String
the SQL query or update that caused the problem (if known)
sql
,
SQLException
the offending SQLException
ex
)

Translate the given SQLException into a generic DataAccessException.

Method Detail

translateback to summary
public DataAccessException translate(String task, String sql, SQLException ex)

Translate the given SQLException into a generic DataAccessException.

The returned DataAccessException is supposed to contain the original SQLException as root cause. However, client code may not generally rely on this due to DataAccessExceptions possibly being caused by other resource APIs as well. That said, a getRootCause() instanceof SQLException check (and subsequent cast) is considered reliable when expecting JDBC-based access to have happened.

Parameters
task:String

readable text describing the task being attempted

sql:String

the SQL query or update that caused the problem (if known)

ex:SQLException

the offending SQLException

Returns:DataAccessException

the DataAccessException wrapping the SQLException, or null if no specific translation could be applied

Annotations
@Nullable
See Also
org.springframework.dao.DataAccessException#getRootCause()