use of java.sql.SQLTimeoutException in project jdk8u_jdk by JetBrains.
the class SQLTimeoutExceptionTests method test1.
/**
* Create SQLTimeoutException with no-arg constructor
*/
@Test
public void test1() {
SQLTimeoutException ex = new SQLTimeoutException();
assertTrue(ex.getMessage() == null && ex.getSQLState() == null && ex.getCause() == null && ex.getErrorCode() == 0);
}
use of java.sql.SQLTimeoutException in project jdk8u_jdk by JetBrains.
the class SQLTimeoutExceptionTests method test7.
/**
* Create SQLTimeoutException with message, and Throwable
*/
@Test
public void test7() {
SQLTimeoutException ex = new SQLTimeoutException(reason, t);
assertTrue(ex.getMessage().equals(reason) && ex.getSQLState() == null && cause.equals(ex.getCause().toString()) && ex.getErrorCode() == 0);
}
use of java.sql.SQLTimeoutException in project jdk8u_jdk by JetBrains.
the class SQLTimeoutExceptionTests method test12.
/**
* Validate that the ordering of the returned Exceptions is correct
* using traditional while loop
*/
@Test
public void test12() {
SQLTimeoutException ex = new SQLTimeoutException("Exception 1", t1);
SQLTimeoutException ex1 = new SQLTimeoutException("Exception 2");
SQLTimeoutException ex2 = new SQLTimeoutException("Exception 3", t2);
ex.setNextException(ex1);
ex.setNextException(ex2);
int num = 0;
SQLException sqe = ex;
while (sqe != null) {
assertTrue(msgs[num++].equals(sqe.getMessage()));
Throwable c = sqe.getCause();
while (c != null) {
assertTrue(msgs[num++].equals(c.getMessage()));
c = c.getCause();
}
sqe = sqe.getNextException();
}
}
use of java.sql.SQLTimeoutException in project jaybird by FirebirdSQL.
the class WireDatabaseConnectionTest method testConnectTimeout_noResponse.
/**
* Tests the connect timeout if the server does not respond.
*/
@Test
public void testConnectTimeout_noResponse() throws Exception {
BlackholeServer server = new BlackholeServer();
Thread thread = new Thread(server);
thread.start();
long startTime = System.currentTimeMillis();
try {
connectionInfo.setPortNumber(server.getPort());
connectionInfo.setDatabaseName("somedb");
connectionInfo.setConnectTimeout(2);
WireDatabaseConnection gdsConnection = new WireDatabaseConnection(connectionInfo);
gdsConnection.socketConnect();
gdsConnection.identify();
fail("Expected connection to fail");
} catch (SQLTimeoutException e) {
long endTime = System.currentTimeMillis();
long difference = endTime - startTime;
assertEquals("Expected error code for \"Unable to complete network request\"", 335544721, e.getErrorCode());
assertEquals("Unexpected timeout duration (in ms)", 2000, difference, TIMEOUT_DELTA_MS);
} catch (SQLException e) {
e.printStackTrace();
fail("Expected SQLTimeoutException to be thrown");
} finally {
server.stop();
thread.join();
}
}
use of java.sql.SQLTimeoutException in project derby by apache.
the class SQLExceptionFactory method getSQLException.
/**
* <p>
* method to construct SQLException
* version specific drivers can overload this method to create
* version specific exceptions
* </p>
*
* <p>
* This implementation creates JDBC 4 exceptions.
* </p>
*
* <pre>
* SQLSTATE CLASS (prefix) Exception
* 0A java.sql.SQLFeatureNotSupportedException
* 08 java.sql.SQLNonTransientConnectionException
* 22 java.sql.SQLDataException
* 28 java.sql.SQLInvalidAuthorizationSpecException
* 40 java.sql.SQLTransactionRollbackException
* 42 java.sql.SQLSyntaxErrorException
* </pre>
*/
@Override
public SQLException getSQLException(String message, String messageId, SQLException next, int severity, Throwable t, Object... args) {
String sqlState = StandardException.getSQLStateFromIdentifier(messageId);
//
// Create dummy exception which ferries arguments needed to serialize
// SQLExceptions across the DRDA network layer.
//
StandardException ferry = wrapArgsForTransportAcrossDRDA(messageId, t, args);
final SQLException ex;
if (sqlState.startsWith(SQLState.CONNECTIVITY_PREFIX)) {
// no derby sqlstate belongs to
// TransientConnectionException DERBY-3074
ex = new SQLNonTransientConnectionException(message, sqlState, severity, ferry);
} else if (sqlState.startsWith(SQLState.SQL_DATA_PREFIX)) {
ex = new SQLDataException(message, sqlState, severity, ferry);
} else if (sqlState.startsWith(SQLState.INTEGRITY_VIOLATION_PREFIX)) {
if (sqlState.equals(SQLState.LANG_NULL_INTO_NON_NULL))
ex = new SQLIntegrityConstraintViolationException(message, sqlState, severity, ferry);
else if (sqlState.equals(SQLState.LANG_CHECK_CONSTRAINT_VIOLATED))
ex = new DerbySQLIntegrityConstraintViolationException(message, sqlState, severity, ferry, args[1], args[0]);
else
ex = new DerbySQLIntegrityConstraintViolationException(message, sqlState, severity, ferry, args[0], args[1]);
} else if (sqlState.startsWith(SQLState.AUTHORIZATION_SPEC_PREFIX)) {
ex = new SQLInvalidAuthorizationSpecException(message, sqlState, severity, ferry);
} else if (sqlState.startsWith(SQLState.TRANSACTION_PREFIX)) {
ex = new SQLTransactionRollbackException(message, sqlState, severity, ferry);
} else if (sqlState.startsWith(SQLState.LSE_COMPILATION_PREFIX)) {
ex = new SQLSyntaxErrorException(message, sqlState, severity, ferry);
} else if (sqlState.startsWith(SQLState.UNSUPPORTED_PREFIX)) {
ex = new SQLFeatureNotSupportedException(message, sqlState, severity, ferry);
} else if (sqlState.equals(SQLState.LANG_STATEMENT_CANCELLED_OR_TIMED_OUT.substring(0, 5)) || sqlState.equals(SQLState.LOGIN_TIMEOUT.substring(0, 5))) {
ex = new SQLTimeoutException(message, sqlState, severity, ferry);
} else {
ex = new SQLException(message, sqlState, severity, ferry);
}
// If the argument ferry has recorded any extra next exceptions,
// graft them into the parent exception.
SQLException ferriedExceptions = ferry.getNextException();
if (ferriedExceptions != null) {
ex.setNextException(ferriedExceptions);
}
if (next != null) {
ex.setNextException(next);
}
return ex;
}
Aggregations