Example usage for java.sql SQLException SQLException

List of usage examples for java.sql SQLException SQLException

Introduction

In this page you can find the example usage for java.sql SQLException SQLException.

Prototype

public SQLException(String reason, String sqlState, int vendorCode, Throwable cause) 

Source Link

Document

Constructs a SQLException object with a given reason, SQLState, vendorCode and cause.

Usage

From source file:org.seasar.doma.boot.autoconfigure.DomaAutoConfigurationTest.java

@Test
public void testSQLExceptionTranslator() {
    this.context.register(DomaAutoConfiguration.class, DataSourceAutoConfiguration.class);
    this.context.refresh();
    PersistenceExceptionTranslator translator = this.context.getBean(PersistenceExceptionTranslator.class);
    {// w w w.  ja va  2s.  c om
        // Translated by SQLErrorCodeSQLExceptionTranslator
        DataAccessException dataAccessException = translator.translateExceptionIfPossible(new JdbcException(
                Message.DOMA2008, new SQLException("Acquire Lock on H2", "SqlState", 50200, null)));
        assertThat(dataAccessException, is(instanceOf(CannotAcquireLockException.class)));
    }
    {
        // Translated by SQLExceptionSubclassTranslator(fallback)
        DataAccessException dataAccessException = translator.translateExceptionIfPossible(
                new JdbcException(Message.DOMA2008, new SQLTimeoutException("Timeout", "SqlState", -1, null)));
        assertThat(dataAccessException, is(instanceOf(QueryTimeoutException.class)));
    }
    {
        // Translated by SQLStateSQLExceptionTranslator (fallback)
        DataAccessException dataAccessException = translator.translateExceptionIfPossible(
                new JdbcException(Message.DOMA2008, new SQLException("With check violation", "44", -1, null)));
        assertThat(dataAccessException, is(instanceOf(DataIntegrityViolationException.class)));
    }
}