接口 SQLExceptionTranslator
- 所有已知实现类:
AbstractFallbackSQLExceptionTranslator
,SQLErrorCodeSQLExceptionTranslator
,SQLExceptionSubclassTranslator
,SQLStateSQLExceptionTranslator
- 函数接口:
- 这是一个函数接口, 因此可用作 lambda 表达式或方法引用的赋值目标。
@FunctionalInterface 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.- 作者:
- Rod Johnson, Juergen Hoeller
- 另请参阅:
DataAccessException
方法概要
所有方法 实例方法 抽象方法 修饰符和类型 方法 说明 DataAccessException
translate(String task, String sql, SQLException ex)
Translate the givenSQLException
into a genericDataAccessException
.
方法详细资料
translate
@Nullable DataAccessException translate(String task, @Nullable 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.- 参数:
task
- readable text describing the task being attemptedsql
- the SQL query or update that caused the problem (if known)ex
- the offendingSQLException
- 返回:
- 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) - 另请参阅:
NestedRuntimeException.getRootCause()