Search in sources :

Example 16 with SQLNonTransientConnectionException

use of java.sql.SQLNonTransientConnectionException in project jdk8u_jdk by JetBrains.

the class SQLNonTransientConnectionExceptionTests method test.

/**
     * Create SQLNonTransientConnectionException and setting all objects to null
     */
@Test
public void test() {
    SQLNonTransientConnectionException e = new SQLNonTransientConnectionException(null, null, errorCode, null);
    assertTrue(e.getMessage() == null && e.getSQLState() == null && e.getCause() == null && e.getErrorCode() == errorCode);
}
Also used : SQLNonTransientConnectionException(java.sql.SQLNonTransientConnectionException) Test(org.testng.annotations.Test) BaseTest(util.BaseTest)

Example 17 with SQLNonTransientConnectionException

use of java.sql.SQLNonTransientConnectionException in project jdk8u_jdk by JetBrains.

the class SQLNonTransientConnectionExceptionTests method test9.

/**
     * Create SQLNonTransientConnectionException with Throwable
     */
@Test
public void test9() {
    SQLNonTransientConnectionException ex = new SQLNonTransientConnectionException(t);
    assertTrue(ex.getMessage().equals(cause) && ex.getSQLState() == null && cause.equals(ex.getCause().toString()) && ex.getErrorCode() == 0);
}
Also used : SQLNonTransientConnectionException(java.sql.SQLNonTransientConnectionException) Test(org.testng.annotations.Test) BaseTest(util.BaseTest)

Example 18 with SQLNonTransientConnectionException

use of java.sql.SQLNonTransientConnectionException in project jdk8u_jdk by JetBrains.

the class SQLNonTransientConnectionExceptionTests method test2.

/**
     * Create SQLNonTransientConnectionException with message
     */
@Test
public void test2() {
    SQLNonTransientConnectionException ex = new SQLNonTransientConnectionException(reason);
    assertTrue(ex.getMessage().equals(reason) && ex.getSQLState() == null && ex.getCause() == null && ex.getErrorCode() == 0);
}
Also used : SQLNonTransientConnectionException(java.sql.SQLNonTransientConnectionException) Test(org.testng.annotations.Test) BaseTest(util.BaseTest)

Example 19 with SQLNonTransientConnectionException

use of java.sql.SQLNonTransientConnectionException in project jaybird by FirebirdSQL.

the class V12Database method cancelOperation.

@Override
public void cancelOperation(int kind) throws SQLException {
    try {
        if (kind == ISCConstants.fb_cancel_abort) {
            try {
                // In case of abort we forcibly close the connection
                closeConnection();
            } catch (IOException ioe) {
                throw new SQLNonTransientConnectionException("Connection abort failed", ioe);
            }
        } else {
            checkConnected();
            try {
                // We circumvent the normal xdrOut to minimize the chance of interleaved writes
                // TODO We may still need to do separate write / read synchronization to ensure this works correctly
                final ByteArrayOutputStream out = new ByteArrayOutputStream(8);
                final XdrOutputStream xdr = new XdrOutputStream(out, false);
                xdr.writeInt(WireProtocolConstants.op_cancel);
                xdr.writeInt(kind);
                wireOperations.writeDirect(out.toByteArray());
            } catch (IOException ioe) {
                throw new FbExceptionBuilder().exception(ISCConstants.isc_net_write_err).cause(ioe).toSQLException();
            }
        }
    } catch (SQLException ex) {
        exceptionListenerDispatcher.errorOccurred(ex);
        throw ex;
    }
}
Also used : SQLNonTransientConnectionException(java.sql.SQLNonTransientConnectionException) SQLException(java.sql.SQLException) FbExceptionBuilder(org.firebirdsql.gds.ng.FbExceptionBuilder) XdrOutputStream(org.firebirdsql.gds.impl.wire.XdrOutputStream) IOException(java.io.IOException) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Example 20 with SQLNonTransientConnectionException

use of java.sql.SQLNonTransientConnectionException in project derby by apache.

the class StatementEventsTest method testAddNullListener.

/**
 * Test that you don't get a NullPointerException when the listeners are
 * triggered and one of them is null. DERBY-3695
 */
public void testAddNullListener() throws SQLException {
    pooledConnection.addStatementEventListener(null);
    PreparedStatement ps = prepare("VALUES (1)");
    // trigger close event
    ps.close();
    assertEquals(1, closedCount);
    assertEquals(0, errorCount);
    ps = prepare("VALUES (1)");
    connection.close();
    try {
        ps.execute();
        fail("Execute should fail on closed connection");
    } catch (SQLNonTransientConnectionException e) {
        assertSQLState("08003", e);
    }
    assertEquals(1, errorCount);
}
Also used : SQLNonTransientConnectionException(java.sql.SQLNonTransientConnectionException) PreparedStatement(java.sql.PreparedStatement)

Aggregations

SQLNonTransientConnectionException (java.sql.SQLNonTransientConnectionException)22 Test (org.testng.annotations.Test)14 BaseTest (util.BaseTest)14 SQLException (java.sql.SQLException)6 PreparedStatement (java.sql.PreparedStatement)4 SQLFeatureNotSupportedException (java.sql.SQLFeatureNotSupportedException)2 StatementEvent (javax.sql.StatementEvent)2 StatementEventListener (javax.sql.StatementEventListener)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 IOException (java.io.IOException)1 Connection (java.sql.Connection)1 ResultSet (java.sql.ResultSet)1 SQLDataException (java.sql.SQLDataException)1 SQLIntegrityConstraintViolationException (java.sql.SQLIntegrityConstraintViolationException)1 SQLInvalidAuthorizationSpecException (java.sql.SQLInvalidAuthorizationSpecException)1 SQLNonTransientException (java.sql.SQLNonTransientException)1 SQLSyntaxErrorException (java.sql.SQLSyntaxErrorException)1 SQLTimeoutException (java.sql.SQLTimeoutException)1 SQLTransactionRollbackException (java.sql.SQLTransactionRollbackException)1 Statement (java.sql.Statement)1