Package org.springframework.jdbc.support
Interface SQLExceptionTranslator
- All Known Implementing Classes:
AbstractFallbackSQLExceptionTranslator
,SQLErrorCodeSQLExceptionTranslator
,SQLExceptionSubclassTranslator
,SQLStateSQLExceptionTranslator
public interface SQLExceptionTranslator
Strategy interface for translating betweenSQLExceptions
and Spring's data access strategy-agnosticDataAccessException
hierarchy.Implementations can be generic (for example, using
SQLState
codes for JDBC) or wholly proprietary (for example, using Oracle error codes) for greater precision.- Author:
- Rod Johnson, Juergen Hoeller
- See Also:
DataAccessException
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description DataAccessException
translate(String task, String sql, SQLException ex)
Translate the givenSQLException
into a genericDataAccessException
.
Method Detail
translate
DataAccessException translate(String task, String sql, SQLException ex)
Translate the givenSQLException
into a genericDataAccessException
.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, agetRootCause() instanceof SQLException
check (and subsequent cast) is considered reliable when expecting JDBC-based access to have happened.- Parameters:
task
- readable text describing the task being attemptedsql
- the SQL query or update that caused the problem (if known)ex
- the offendingSQLException
- Returns:
- the DataAccessException wrapping the
SQLException
, ornull
if no translation could be applied (in a custom translator; the default translators always throw anUncategorizedSQLException
in such a case) - See Also:
NestedRuntimeException.getRootCause()