Hi,
I am using Spring JdbcTemplate to run my queries.
I ran into some trouble when trying to control the exception thrown by the jdbcTemplate.
With regards to DAO, spring using its own hierarchy of exceptions.
The exceptions thrown are of type DataAccessException.
I want to be able to ignore certain exceptions, for example I run a query which give SQLException, with error code 11111. , I could check the error code and act accordingly.
The DataAccessException doesn't expose such method.
So what I did is to use the getCause method of the exception to investigate the exception (I don't like this solution), Until I get to the SQLException, and take the error code from it.
I tried to extends from SQLErrorCodeSQLExceptionTranslator, and when get a specific error, return null, but it didn't help. the Spring have several mechanisms to handle exceptions after trying to use the custom translators.
Have any idea??Code:public class AdgSQLErrorCodesTranslator extends SQLErrorCodeSQLExceptionTranslator { protected DataAccessException customTranslate(String task, String sql, SQLException sqlex) { if (sqlex.getErrorCode() == 12920) { //Do nothing, ignoring error: database is already in force logging mode } return null; } }
Thanks!!


Reply With Quote
. 