Results 1 to 4 of 4

Thread: Using SQLExceptionTranslator on Sybase

  1. #1
    Join Date
    Feb 2006
    Posts
    2

    Default 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. #2
    Join Date
    Aug 2004
    Posts
    1,104

    Default

    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.
    Thomas Risberg
    SpringSource by Pivotal
    http://www.springsource.org

  3. #3
    Join Date
    Feb 2006
    Posts
    2

    Default

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

  4. #4
    Join Date
    Aug 2004
    Posts
    1,104

    Default

    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.
    Thomas Risberg
    SpringSource by Pivotal
    http://www.springsource.org

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •