Если у вас есть JdbcTemplate
, вы можете сделать
catch (SqlException e) {
throw jdbcTemplate.getExceptionTranslator().translate("my task", null, e);
}
Если у вас нет JdbcTemplate
, просто посмотрите на исходный код метода JdbcTemplate.getExceptionTranslator()
:
public synchronized SQLExceptionTranslator getExceptionTranslator() {
if (this.exceptionTranslator == null) {
DataSource dataSource = getDataSource();
if (dataSource != null) {
this.exceptionTranslator = new SQLErrorCodeSQLExceptionTranslator(dataSource);
}
else {
this.exceptionTranslator = new SQLStateSQLExceptionTranslator();
}
}
return this.exceptionTranslator;
}
И подражать его поведению: -)