spring-framework / org.springframework.jdbc.support / SQLExceptionTranslator / translate

translate

@Nullable abstract fun translate(task: String, @Nullable sql: String, ex: SQLException): DataAccessException

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 - readable text describing the task being attempted

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

ex - the offending SQLException

Return
the DataAccessException wrapping the SQLException, or null if no translation could be applied (in a custom translator; the default translators always throw an org.springframework.jdbc.UncategorizedSQLException in such a case)

See Also
org.springframework.dao.DataAccessException#getRootCause()