当前位置: 首页>>代码示例>>Java>>正文


Java SQLTimeoutException类代码示例

本文整理汇总了Java中java.sql.SQLTimeoutException的典型用法代码示例。如果您正苦于以下问题:Java SQLTimeoutException类的具体用法?Java SQLTimeoutException怎么用?Java SQLTimeoutException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


SQLTimeoutException类属于java.sql包,在下文中一共展示了SQLTimeoutException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: doCommand

import java.sql.SQLTimeoutException; //导入依赖的package包/类
/**
 * 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, 1, 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;
}
 
开发者ID:CoffeeCodeSwitzerland,项目名称:Lernkartei_2017,代码行数:27,代码来源:DBDriver.java

示例2: test12

import java.sql.SQLTimeoutException; //导入依赖的package包/类
/**
 * 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();
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:24,代码来源:SQLTimeoutExceptionTests.java

示例3: isCausedByTimeoutException

import java.sql.SQLTimeoutException; //导入依赖的package包/类
/**
 * <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;
}
 
开发者ID:alfasoftware,项目名称:morf,代码行数:25,代码来源:DatabaseExceptionHelper.java

示例4: testSqlError

import java.sql.SQLTimeoutException; //导入依赖的package包/类
@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, "sqlError");
    assertEquals(ResourceException.INTERNAL_SERVER_ERROR, rEx.getCode());

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

    jdbcConn.close();
}
 
开发者ID:yahoo,项目名称:athenz,代码行数:20,代码来源:JDBCCertRecordStoreConnectionTest.java

示例5: testExecuteQueryTimeout

import java.sql.SQLTimeoutException; //导入依赖的package包/类
/**
 * @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"
    );
}
 
开发者ID:apache,项目名称:ignite,代码行数:22,代码来源:JdbcThinStatementSelfTest.java

示例6: testExecuteUpdateTimeout

import java.sql.SQLTimeoutException; //导入依赖的package包/类
/**
 * @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);
            }
        },
        SQLTimeoutException.class,
        "Timeout"
    );
}
 
开发者ID:apache,项目名称:ignite,代码行数:22,代码来源:JdbcThinStatementSelfTest.java

示例7: createSQLException

import java.sql.SQLTimeoutException; //导入依赖的package包/类
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.",
                    poolName, elapsedMs), SQLSTATE_TIMEOUT_ERROR, intElapsedMs) :
            new SQLException(format("Pool %s, interrupted while getting SQL connection, waited for %.3f ms.",
                    poolName, elapsedMs), SQLSTATE_INTERRUPTED_ERROR, intElapsedMs);
}
 
开发者ID:vibur,项目名称:vibur-dbcp,代码行数:19,代码来源:PoolOperations.java

示例8: wait

import java.sql.SQLTimeoutException; //导入依赖的package包/类
/**
 * 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");
            }
        }
    }
}
 
开发者ID:milesibastos,项目名称:jTDS,代码行数:28,代码来源:TdsCore.java

示例9: test_Constructor_LThrowable

import java.sql.SQLTimeoutException; //导入依赖的package包/类
/**
 * @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());
}
 
开发者ID:shannah,项目名称:cn1,代码行数:20,代码来源:SQLTimeoutExceptionTest.java

示例10: test_Constructor_LStringLThrowable

import java.sql.SQLTimeoutException; //导入依赖的package包/类
/**
 * @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",
            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());
}
 
开发者ID:shannah,项目名称:cn1,代码行数:20,代码来源:SQLTimeoutExceptionTest.java

示例11: test_Constructor_LStringLStringLThrowable

import java.sql.SQLTimeoutException; //导入依赖的package包/类
/**
 * @test java.sql.SQLTimeoutException(String, 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",
            "MYTESTSTRING2", 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",
            sQLTimeoutException.getErrorCode(), 0);
    assertEquals(
            "The cause of SQLTimeoutException set and get should be equivalent",
            cause, sQLTimeoutException.getCause());
}
 
开发者ID:shannah,项目名称:cn1,代码行数:21,代码来源:SQLTimeoutExceptionTest.java

示例12: test_Constructor_LStringLStringLThrowable_1

import java.sql.SQLTimeoutException; //导入依赖的package包/类
/**
 * @test java.sql.SQLTimeoutException(String, String, Throwable)
 */
public void test_Constructor_LStringLStringLThrowable_1() {
    SQLTimeoutException sQLTimeoutException = new SQLTimeoutException(
            "MYTESTSTRING1", "MYTESTSTRING2", null);
    assertNotNull(sQLTimeoutException);
    assertEquals(
            "The SQLState of SQLTimeoutException set and get should be equivalent",
            "MYTESTSTRING2", 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",
            sQLTimeoutException.getErrorCode(), 0);
    assertNull("The cause of SQLTimeoutException should be null",
            sQLTimeoutException.getCause());
}
 
开发者ID:shannah,项目名称:cn1,代码行数:19,代码来源:SQLTimeoutExceptionTest.java

示例13: test_Constructor_LStringLStringLThrowable_2

import java.sql.SQLTimeoutException; //导入依赖的package包/类
/**
 * @test java.sql.SQLTimeoutException(String, String, 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",
            sQLTimeoutException.getSQLState());
    assertEquals(
            "The reason of SQLTimeoutException set and get should be equivalent",
            "MYTESTSTRING", sQLTimeoutException.getMessage());
    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());
}
 
开发者ID:shannah,项目名称:cn1,代码行数:20,代码来源:SQLTimeoutExceptionTest.java

示例14: test_Constructor_LStringLStringLThrowable_4

import java.sql.SQLTimeoutException; //导入依赖的package包/类
/**
 * @test java.sql.SQLTimeoutException(String, String, Throwable)
 */
public void test_Constructor_LStringLStringLThrowable_4() {
    Throwable cause = new Exception("MYTHROWABLE");
    SQLTimeoutException sQLTimeoutException = new SQLTimeoutException(null,
            "MYTESTSTRING", cause);
    assertNotNull(sQLTimeoutException);
    assertEquals(
            "The SQLState of SQLTimeoutException set and get should be equivalent",
            "MYTESTSTRING", sQLTimeoutException.getSQLState());
    assertNull("The reason of SQLTimeoutException should be null",
            sQLTimeoutException.getMessage());
    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());
}
 
开发者ID:shannah,项目名称:cn1,代码行数:20,代码来源:SQLTimeoutExceptionTest.java

示例15: test_Constructor_LStringLStringLThrowable_6

import java.sql.SQLTimeoutException; //导入依赖的package包/类
/**
 * @test java.sql.SQLTimeoutException(String, String, Throwable)
 */
public void test_Constructor_LStringLStringLThrowable_6() {
    Throwable cause = new Exception("MYTHROWABLE");
    SQLTimeoutException sQLTimeoutException = new SQLTimeoutException(null,
            null, cause);
    assertNotNull(sQLTimeoutException);
    assertNull("The SQLState of SQLTimeoutException should be null",
            sQLTimeoutException.getSQLState());
    assertNull("The reason of SQLTimeoutException should be null",
            sQLTimeoutException.getMessage());
    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());
}
 
开发者ID:shannah,项目名称:cn1,代码行数:19,代码来源:SQLTimeoutExceptionTest.java


注:本文中的java.sql.SQLTimeoutException类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。