Announcement Announcement Module
Collapse
No announcement yet.
Using SQLExceptionTranslator on Sybase Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Using SQLExceptionTranslator on Sybase

    Hi,

    I am using the SQLExceptionTranslator interface to parse my SQLException. In Sybase when the database is not available I get an Error Code 0 and SQL State JZ006.

    However, in Sybase the Error code 0 is returned for few other exceptions like Query timeout.

    How can I make sure that the Sybase DB is not available?

    In Oracle the Error code translator gives me DataAccessResourceFailureException for database not available which serves my purpose. I want something similar for Sybase.

    Thanks in advance.

  • #2
    The only solution right now would be to use the sql state code for translation. You would have to customize sql-error-codes.xml and set the flag useSqlStateForTranslation - look at the Postgres entry which already does this. Drawback is that now you have to use the sql state code for all translations - it's a global setting for the database type.

    Comment


    • #3
      Thanks for the reply.
      So, I need to extend the class SQLStateSQLExceptionTranslator and throw the corresponding exception for JZ006.

      Comment


      • #4
        You could do that - that's not what I mentioned, but on second thought that's a better option for you. Might look like this:

        Code:
            public class CustomErrorCodesTranslator
                    extends SQLErrorCodeSQLExceptionTranslator {
        
                protected DataAccessException customTranslate(String task, String sql,
                                                              SQLException sqlex) {
                    if (sqlex.getErrorCode() == 0 && "JZ006".equals(sqlex.getSQLState())) {
                        return new DataAccessResourceFailureException("Database down", sqlex);
                    }
                    return null;
                }
            }
        And then you would have to set this on the JdbcTemplate you are using.

        Comment

        Working...
        X