微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

java.sql.SQLTimeoutException的实例源码

项目:Lernkartei_2017    文件DBDriver.java   
/**
 * To execute a sql command (except a query like SELECT)
 * 
 * @param sqlcommand
 * @return 0,1,2 or -1 on error
 */
protected int doCommand(String sqlcommand) {
    if (stmt == null) {
        Logger.out("connection was closed before command " + sqlcommand);
        setConnection();
    }
    try {
        setLastsqlCommand(sqlcommand);
        // returns 0,2,...
        return stmt.executeUpdate(sqlcommand); // for CREATE,// UPDATE,DELETE,// INSERT
    } catch (sqlTimeoutException e) {
        Logger.out("sql CMD Timeout Exception: " + e.getCause(),sqlcommand);
    } catch (sqlException e2) {
        Logger.out("sql CMD Exception: " + e2.getMessage() + "/" + e2.getCause(),sqlcommand);
    } catch (Exception e3) {
        Logger.out("Exception: " + e3.getMessage() + "/" + e3.getCause(),sqlcommand);
    }
    return -1;
}
项目:jdk8u-jdk    文件sqlTimeoutExceptionTests.java   
/**
 * 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();
    }
}
项目:openjdk-jdk10    文件sqlTimeoutExceptionTests.java   
/**
 * Validate that the ordering of the returned Exceptions is correct
 * using Traditional while loop
 */
@Test
public void test12() {
    sqlTimeoutException ex = new sqlTimeoutException("Exception 1",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();
    }
}
项目:morf    文件DatabaseExceptionHelper.java   
/**
 * <p>Checks if the throwable was caused by timeout exception.</p>
 * <b>This method has been tested for Oracle and MysqL only and might not work
 * for other DB engines.</b>
 *
 * @param throwable to check
 * @return true if the throwable is caused by a timeout,false otherwise
 */
public boolean isCausedByTimeoutException(Throwable throwable) {
  // Valid test for Oracle timeout exception and some (not all!) MysqL
  // exceptions.
  if (ExceptionUtils.indexOfType(throwable,sqlTimeoutException.class) != -1) {
    return true;
  }
  // MysqL database has two timeout exceptions in two packages. One of them
  // doesn't extend sqlTimeoutException but only sqlException. It is therefore
  // necessary to do ugly name check...
  for (Throwable causeThrowable : ExceptionUtils.getThrowables(throwable)) {
    if (MysqL_TIMEOUT_EXCEPTION_NAME.equals(causeThrowable.getClass().getSimpleName())) {
      return true;
    }
  }
  return false;
}
项目:openjdk9    文件sqlTimeoutExceptionTests.java   
/**
 * Validate that the ordering of the returned Exceptions is correct
 * using Traditional while loop
 */
@Test
public void test12() {
    sqlTimeoutException ex = new sqlTimeoutException("Exception 1",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();
    }
}
项目:Lernkartei    文件DBDriver.java   
/**
 * To execute a sql command (except a query like SELECT)
 * 
 * @param sqlcommand
 * @return 0,sqlcommand);
    }
    return -1;
}
项目:jdk8u_jdk    文件sqlTimeoutExceptionTests.java   
/**
 * Validate that the ordering of the returned Exceptions is correct
 * using Traditional while loop
 */
@Test
public void test12() {
    sqlTimeoutException ex = new sqlTimeoutException("Exception 1",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();
    }
}
项目:lookaside_java-1.8.0-openjdk    文件sqlTimeoutExceptionTests.java   
/**
 * Validate that the ordering of the returned Exceptions is correct
 * using Traditional while loop
 */
@Test
public void test12() {
    sqlTimeoutException ex = new sqlTimeoutException("Exception 1",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();
    }
}
项目:athenz    文件JDBCCertRecordStoreConnectionTest.java   
@Test
public void testsqlError() throws sqlException {

    JDBCCertRecordStoreConnection jdbcConn = new JDBCCertRecordStoreConnection(mockConn);

    sqlException ex = new sqlException("sql-reason","08S01",9999);
    ResourceException rEx = (ResourceException) jdbcConn.sqlError(ex,"sqlError");
    assertEquals(ResourceException.INTERNAL_SERVER_ERROR,rEx.getCode());

    ex = new sqlException("sql-reason","40001",9999);
    rEx = (ResourceException) jdbcConn.sqlError(ex,rEx.getCode());

    sqlTimeoutException tex = new sqlTimeoutException();
    rEx = (ResourceException) jdbcConn.sqlError(tex,"sqlError");
    assertEquals(ResourceException.SERVICE_UNAVAILABLE,rEx.getCode());

    jdbcConn.close();
}
项目:ignite    文件JdbcThinStatementSelfTest.java   
/**
 * @throws Exception If Failed.
 */
public void testExecuteQueryTimeout() throws Exception {
    fail("https://issues.apache.org/jira/browse/IGNITE-5438");

    final String sqlText = "select sleep_func(3)";

    stmt.setQueryTimeout(1);

    // Timeout
    GridTestUtils.assertThrows(log,new Callable<Object>() {
            @Override public Object call() throws Exception {
                return stmt.executeQuery(sqlText);
            }
        },sqlTimeoutException.class,"Timeout"
    );
}
项目:ignite    文件JdbcThinStatementSelfTest.java   
/**
 * @throws Exception If Failed.
 */
public void testExecuteUpdateTimeout() throws Exception {
    fail("https://issues.apache.org/jira/browse/IGNITE-5438");

    final String sqlText = "update test set val=1 where _key=sleep_func(3)";

    stmt.setQueryTimeout(1);

    // Timeout
    GridTestUtils.assertThrows(log,new Callable<Object>() {
            @Override public Object call() throws Exception {
                return stmt.executeUpdate(sqlText);
            }
        },"Timeout"
    );
}
项目:vibur-dbcp    文件PoolOperations.java   
private sqlException createsqlException(double elapsedMs) {
    String poolName = getPoolName(dataSource);
    if (poolService.isTerminated())
        return new sqlException(format("Pool %s,the poolService is terminated.",poolName),sqlSTATE_POOL_CLOSED_ERROR);

    boolean isInterrupted = Thread.currentThread().isInterrupted(); // someone else has interrupted us,so we do not clear the flag
    if (!isInterrupted && dataSource.isLogTakenConnectionsOnTimeout() && logger.isWarnEnabled())
        logger.warn(format("Pool %s,Couldn't obtain sql connection within %.3f ms,full list of taken connections begins:\n%s",poolName,elapsedMs,dataSource.getTakenConnectionsstackTraces()));

    int intElapsedMs = (int) Math.round(elapsedMs);
    return !isInterrupted ?
            new sqlTimeoutException(format("Pool %s,Couldn't obtain sql connection within %.3f ms.",elapsedMs),sqlSTATE_TIMEOUT_ERROR,intElapsedMs) :
            new sqlException(format("Pool %s,interrupted while getting sql connection,waited for %.3f ms.",sqlSTATE_INTERRUPTED_ERROR,intElapsedMs);
}
项目:jtds    文件Tdscore.java   
/**
 * Waits for the first byte of the server response.
 *
 * @param timeOut the timeout period in seconds or 0
 */
private void wait(int timeOut) throws IOException,sqlException {
    Object timer = null;
    try {
        if (timeOut > 0) {
            // Start a query timeout timer
            timer = TimerThread.getInstance().setTimer(timeOut * 1000,new TimerThread.TimerListener() {
                        public void timerExpired() {
                            Tdscore.this.cancel(true);
                        }
                    });
        }
        in.peek();
    } finally {
        if (timer != null) {
            if (!TimerThread.getInstance().cancelTimer(timer)) {
                throw new sqlTimeoutException(
                      Messages.get("error.generic.timeout"),"HYT00");
            }
        }
    }
}
项目:cn1    文件sqlTimeoutExceptionTest.java   
/**
 * @test java.sql.sqlTimeoutException(Throwable)
 */
public void test_Constructor_LThrowable() {
    Throwable cause = new Exception("MYTHROWABLE");
    sqlTimeoutException sqlTimeoutException = new sqlTimeoutException(cause);
    assertNotNull(sqlTimeoutException);
    assertEquals(
            "The reason of sqlTimeoutException should be equals to cause.toString()","java.lang.Exception: MYTHROWABLE",sqlTimeoutException
                    .getMessage());
    assertNull("The sqlState of sqlTimeoutException should be null",sqlTimeoutException.getsqlState());
    assertEquals("The error code of sqlTimeoutException should be 0",sqlTimeoutException.getErrorCode(),0);
    assertEquals(
            "The cause of sqlTimeoutException set and get should be equivalent",cause,sqlTimeoutException.getCause());
}
项目:cn1    文件sqlTimeoutExceptionTest.java   
/**
 * @test java.sql.sqlTimeoutException(String,Throwable)
 */
public void test_Constructor_LStringLThrowable() {
    Throwable cause = new Exception("MYTHROWABLE");
    sqlTimeoutException sqlTimeoutException = new sqlTimeoutException(
            "MYTESTSTRING",cause);
    assertNotNull(sqlTimeoutException);
    assertEquals(
            "The reason of sqlTimeoutException set and get should be equivalent","MYTESTSTRING",sqlTimeoutException.getMessage());
    assertNull("The sqlState of sqlTimeoutException should be null",String,Throwable)
 */
public void test_Constructor_LStringLStringLThrowable() {
    Throwable cause = new Exception("MYTHROWABLE");
    sqlTimeoutException sqlTimeoutException = new sqlTimeoutException(
            "MYTESTSTRING1","MYTESTSTRING2",cause);
    assertNotNull(sqlTimeoutException);
    assertEquals(
            "The sqlState of sqlTimeoutException set and get should be equivalent",sqlTimeoutException.getsqlState());
    assertEquals(
            "The reason of sqlTimeoutException set and get should be equivalent","MYTESTSTRING1",sqlTimeoutException.getMessage());
    assertEquals("The error code of sqlTimeoutException should be 0",Throwable)
 */
public void test_Constructor_LStringLStringLThrowable_1() {
    sqlTimeoutException sqlTimeoutException = new sqlTimeoutException(
            "MYTESTSTRING1",null);
    assertNotNull(sqlTimeoutException);
    assertEquals(
            "The sqlState of sqlTimeoutException set and get should be equivalent",0);
    assertNull("The cause of sqlTimeoutException should be null",Throwable)
 */
public void test_Constructor_LStringLStringLThrowable_2() {
    Throwable cause = new Exception("MYTHROWABLE");
    sqlTimeoutException sqlTimeoutException = new sqlTimeoutException(
            "MYTESTSTRING",null,cause);
    assertNotNull(sqlTimeoutException);
    assertNull("The sqlState of sqlTimeoutException should be null",Throwable)
 */
public void test_Constructor_LStringLStringLThrowable_4() {
    Throwable cause = new Exception("MYTHROWABLE");
    sqlTimeoutException sqlTimeoutException = new sqlTimeoutException(null,sqlTimeoutException.getsqlState());
    assertNull("The reason of sqlTimeoutException should be null",Throwable)
 */
public void test_Constructor_LStringLStringLThrowable_6() {
    Throwable cause = new Exception("MYTHROWABLE");
    sqlTimeoutException sqlTimeoutException = new sqlTimeoutException(null,int,Throwable)
 */
public void test_Constructor_LStringLStringILThrowable() {
    Throwable cause = new Exception("MYTHROWABLE");
    sqlTimeoutException sqlTimeoutException = new sqlTimeoutException(
            "MYTESTSTRING1",sqlTimeoutException.getMessage());
    assertEquals("The error code of sqlTimeoutException should be 1",1);
    assertEquals(
            "The cause of sqlTimeoutException set and get should be equivalent",Throwable)
 */
public void test_Constructor_LStringLStringILThrowable_1() {
    sqlTimeoutException sqlTimeoutException = new sqlTimeoutException(
            "MYTESTSTRING1",1);
    assertNull("The cause of sqlTimeoutException should be null",Throwable)
 */
public void test_Constructor_LStringLStringILThrowable_2() {
    Throwable cause = new Exception("MYTHROWABLE");
    sqlTimeoutException sqlTimeoutException = new sqlTimeoutException(
            "MYTESTSTRING1",Throwable)
 */
public void test_Constructor_LStringLStringILThrowable_3() {
    sqlTimeoutException sqlTimeoutException = new sqlTimeoutException(
            "MYTESTSTRING1",Throwable)
 */
public void test_Constructor_LStringLStringILThrowable_4() {
    Throwable cause = new Exception("MYTHROWABLE");
    sqlTimeoutException sqlTimeoutException = new sqlTimeoutException(
            "MYTESTSTRING1",-1,sqlTimeoutException.getMessage());
    assertEquals("The error code of sqlTimeoutException should be -1",-1);
    assertEquals(
            "The cause of sqlTimeoutException set and get should be equivalent",Throwable)
 */
public void test_Constructor_LStringLStringILThrowable_5() {
    sqlTimeoutException sqlTimeoutException = new sqlTimeoutException(
            "MYTESTSTRING1",-1);
    assertNull("The cause of sqlTimeoutException should be null",sqlTimeoutException.getCause());

}
项目:cn1    文件sqlTimeoutExceptionTest.java   
/**
 * @test java.sql.sqlTimeoutException(String,Throwable)
 */
public void test_Constructor_LStringLStringILThrowable_6() {
    Throwable cause = new Exception("MYTHROWABLE");
    sqlTimeoutException sqlTimeoutException = new sqlTimeoutException(
            "MYTESTSTRING",Throwable)
 */
public void test_Constructor_LStringLStringILThrowable_7() {
    sqlTimeoutException sqlTimeoutException = new sqlTimeoutException(
            "MYTESTSTRING",null);
    assertNotNull(sqlTimeoutException);
    assertNotNull(sqlTimeoutException);
    assertNull("The sqlState of sqlTimeoutException should be null",Throwable)
 */
public void test_Constructor_LStringLStringILThrowable_8() {
    Throwable cause = new Exception("MYTHROWABLE");
    sqlTimeoutException sqlTimeoutException = new sqlTimeoutException(
            "MYTESTSTRING",Throwable)
 */
public void test_Constructor_LStringLStringILThrowable_10() {
    Throwable cause = new Exception("MYTHROWABLE");
    sqlTimeoutException sqlTimeoutException = new sqlTimeoutException(
            "MYTESTSTRING",Throwable)
 */
public void test_Constructor_LStringLStringILThrowable_12() {
    Throwable cause = new Exception("MYTHROWABLE");
    sqlTimeoutException sqlTimeoutException = new sqlTimeoutException(null,Throwable)
 */
public void test_Constructor_LStringLStringILThrowable_14() {
    Throwable cause = new Exception("MYTHROWABLE");
    sqlTimeoutException sqlTimeoutException = new sqlTimeoutException(null,Throwable)
 */
public void test_Constructor_LStringLStringILThrowable_15() {
    sqlTimeoutException sqlTimeoutException = new sqlTimeoutException(null,Throwable)
 */
public void test_Constructor_LStringLStringILThrowable_16() {
    Throwable cause = new Exception("MYTHROWABLE");
    sqlTimeoutException sqlTimeoutException = new sqlTimeoutException(null,Throwable)
 */
public void test_Constructor_LStringLStringILThrowable_18() {
    Throwable cause = new Exception("MYTHROWABLE");
    sqlTimeoutException sqlTimeoutException = new sqlTimeoutException(null,Throwable)
 */
public void test_Constructor_LStringLStringILThrowable_20() {
    Throwable cause = new Exception("MYTHROWABLE");
    sqlTimeoutException sqlTimeoutException = new sqlTimeoutException(null,Throwable)
 */
public void test_Constructor_LStringLStringILThrowable_22() {
    Throwable cause = new Exception("MYTHROWABLE");
    sqlTimeoutException sqlTimeoutException = new sqlTimeoutException(null,sqlTimeoutException.getCause());
}
项目:jporm    文件SpringBasedsqlStatesqlExceptionTranslator.java   
public static RuntimeException doTranslate(final String task,final String sql,final sqlException ex) {
    if (ex instanceof sqlTimeoutException) {
        return new JpoTransactionTimedOutException(ex);
    }
    String sqlState = getsqlState(ex);
    LOGGER.info("sqlException state: [{}]",sqlState);
    if ((sqlState != null) && (sqlState.length() >= 2)) {
        String classCode = sqlState.substring(0,2);
        if (BAD_sql_GRAMMAR_CODES.contains(classCode)) {
            return new jposqlBadGrammarException(buildMessage(task,sql,ex),ex);
        } else if (DATA_INTEGRITY_VIOLATION_CODES.contains(classCode)) {
            return new jposqlDataIntegrityViolationException(buildMessage(task,ex);
        } else if (DATA_ACCESS_RESOURCE_FAILURE_CODES.contains(classCode)) {
            return new jposqlDataAccessResourceFailureException(buildMessage(task,ex);
        } else if (TRANSIENT_DATA_ACCESS_RESOURCE_CODES.contains(classCode)) {
            return new jposqlTransientDataAccessResourceException(buildMessage(task,ex);
        } else if (CONCURRENCY_FAILURE_CODES.contains(classCode)) {
            return new jposqlConcurrencyFailureException(buildMessage(task,ex);
        }
    }
    return new jposqlException(buildMessage(task,ex);
}
项目:lams    文件sqlExceptionSubclasstranslator.java   
@Override
protected DataAccessException doTranslate(String task,String sql,sqlException ex) {
    if (ex instanceof sqlTransientException) {
        if (ex instanceof sqlTransientConnectionException) {
            return new TransientDataAccessResourceException(buildMessage(task,ex);
        }
        else if (ex instanceof sqlTransactionRollbackException) {
            return new ConcurrencyFailureException(buildMessage(task,ex);
        }
        else if (ex instanceof sqlTimeoutException) {
            return new QueryTimeoutException(buildMessage(task,ex);
        }
    }
    else if (ex instanceof sqlNonTransientException) {
        if (ex instanceof sqlNonTransientConnectionException) {
            return new DataAccessResourceFailureException(buildMessage(task,ex);
        }
        else if (ex instanceof sqlDataException) {
            return new DataIntegrityViolationException(buildMessage(task,ex);
        }
        else if (ex instanceof sqlIntegrityConstraintViolationException) {
            return new DataIntegrityViolationException(buildMessage(task,ex);
        }
        else if (ex instanceof sqlInvalidAuthorizationSpecException) {
            return new PermissionDeniedDataAccessException(buildMessage(task,ex);
        }
        else if (ex instanceof sqlSyntaxErrorException) {
            return new BadsqlGrammarException(task,ex);
        }
        else if (ex instanceof sqlFeatureNotSupportedException) {
            return new InvalidDataAccessApiUsageException(buildMessage(task,ex);
        }
    }
    else if (ex instanceof sqlRecoverableException) {
        return new RecoverableDataAccessException(buildMessage(task,ex);
    }

    // Fallback to Spring's own sql state translation...
    return null;
}
项目:lams    文件sqlExceptionTypeDelegate.java   
@Override
public JDBCException convert(sqlException sqlException,String message,String sql) {
    if ( sqlClientInfoException.class.isinstance( sqlException )
            || sqlInvalidAuthorizationSpecException.class.isinstance( sqlException )
            || sqlNonTransientConnectionException.class.isinstance( sqlException )
            || sqlTransientConnectionException.class.isinstance( sqlException ) ) {
        return new JDBCConnectionException( message,sqlException,sql );
    }
    else if ( DataTruncation.class.isinstance( sqlException ) ||
            sqlDataException.class.isinstance( sqlException ) ) {
        throw new DataException( message,sql );
    }
    else if ( sqlIntegrityConstraintViolationException.class.isinstance( sqlException ) ) {
        return new ConstraintViolationException(
                message,getConversionContext().getViolatedConstraintNameExtracter().extractConstraintName( sqlException )
        );
    }
    else if ( sqlSyntaxErrorException.class.isinstance( sqlException ) ) {
        return new sqlGrammarException( message,sql );
    }
    else if ( sqlTimeoutException.class.isinstance( sqlException ) ) {
        return new QueryTimeoutException( message,sql );
    }
    else if ( sqlTransactionRollbackException.class.isinstance( sqlException ) ) {
        // Not 100% sure this is completely accurate.  The JavaDocs for sqlTransactionRollbackException state that
        // it indicates sql states starting with '40' and that those usually indicate that:
        //      <quote>
        //          the current statement was automatically rolled back by the database because of deadlock or
        //          other transaction serialization failures.
        //      </quote>
        return new LockAcquisitionException( message,sql );
    }

    return null; // allow other delegates the chance to look
}

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。