com.mysql.jdbc.exceptions.MySQLTimeoutException Java Examples

The following examples show how to use com.mysql.jdbc.exceptions.MySQLTimeoutException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: StatementImpl.java    From r-course with MIT License 6 votes vote down vote up
protected SQLException handleExceptionForBatch(int endOfBatchIndex, int numValuesPerBatch, long[] updateCounts, SQLException ex)
        throws BatchUpdateException, SQLException {
    for (int j = endOfBatchIndex; j > endOfBatchIndex - numValuesPerBatch; j--) {
        updateCounts[j] = EXECUTE_FAILED;
    }

    if (this.continueBatchOnError && !(ex instanceof MySQLTimeoutException) && !(ex instanceof MySQLStatementCancelledException)
            && !hasDeadlockOrTimeoutRolledBackTx(ex)) {
        return ex;
    } // else: throw the exception immediately

    long[] newUpdateCounts = new long[endOfBatchIndex];
    System.arraycopy(updateCounts, 0, newUpdateCounts, 0, endOfBatchIndex);

    throw SQLError.createBatchUpdateException(ex, newUpdateCounts, getExceptionInterceptor());
}
 
Example #2
Source File: StatementImpl.java    From Komondor with GNU General Public License v3.0 6 votes vote down vote up
protected SQLException handleExceptionForBatch(int endOfBatchIndex, int numValuesPerBatch, long[] updateCounts, SQLException ex)
        throws BatchUpdateException, SQLException {
    for (int j = endOfBatchIndex; j > endOfBatchIndex - numValuesPerBatch; j--) {
        updateCounts[j] = EXECUTE_FAILED;
    }

    if (this.continueBatchOnError && !(ex instanceof MySQLTimeoutException) && !(ex instanceof MySQLStatementCancelledException)
            && !hasDeadlockOrTimeoutRolledBackTx(ex)) {
        return ex;
    } // else: throw the exception immediately

    long[] newUpdateCounts = new long[endOfBatchIndex];
    System.arraycopy(updateCounts, 0, newUpdateCounts, 0, endOfBatchIndex);

    throw SQLError.createBatchUpdateException(ex, newUpdateCounts, getExceptionInterceptor());
}
 
Example #3
Source File: TimeoutDetectorTest.java    From dal with Apache License 2.0 5 votes vote down vote up
private SQLException mockTimeoutException(DatabaseCategory category){
	if(category == DatabaseCategory.MySql){
		return new MySQLTimeoutException("Test mysql timeout excption");
	}
	else{
		category = DatabaseCategory.SqlServer;
		return new SQLException("The query has timed out");
	}
}
 
Example #4
Source File: HeartBeatDaoImpl.java    From DBus with Apache License 2.0 4 votes vote down vote up
private int sendRdbmsPacket(String key, String dsName, String schemaName, String tableName, String packet, String dsType) {
    Connection conn = null;
    PreparedStatement ps = null;
    int cnt = 0;
    long beginConn = 0, endConn = 0, beginStmt = 0, endStmt = 0, closeConn = 0, closeEndConn = 0;
    try {
        beginConn = System.currentTimeMillis();
        conn = DataSourceContainer.getInstance().getConn(key);
        endConn = System.currentTimeMillis();
        if (StringUtils.equals(Constants.CONFIG_DB_TYPE_MYSQL, dsType)) {
            ps = conn.prepareStatement(getSendPacketSql2Mysql());
            ps.setString(1, dsName);
            ps.setString(2, schemaName);
            ps.setString(3, tableName);
            ps.setString(4, packet);
            ps.setString(5, DateUtil.convertLongToStr4Date(System.currentTimeMillis()));
            ps.setString(6, DateUtil.convertLongToStr4Date(System.currentTimeMillis()));
        } else if (StringUtils.equals(Constants.CONFIG_DB_TYPE_ORA, dsType)) {
            ps = conn.prepareStatement(getSendPacketSql2Oracle());
            ps.setString(1, dsName);
            ps.setString(2, schemaName);
            ps.setString(3, tableName);
            ps.setString(4, packet);
        } else if (StringUtils.equals(Constants.CONFIG_DB_TYPE_DB2, dsType)) {
            ps = conn.prepareStatement(getSendPacketSql2DB2());
            ps.setString(1, dsName);
            ps.setString(2, schemaName);
            ps.setString(3, tableName);
            ps.setString(4, packet);
        }

        Integer queryTimeout = HeartBeatConfigContainer.getInstance().getHbConf().getQueryTimeout();
        if (queryTimeout == null) queryTimeout = 5;
        ps.setQueryTimeout(queryTimeout);

        beginStmt = System.currentTimeMillis();
        cnt = ps.executeUpdate();
        endStmt = System.currentTimeMillis();
    } catch (Exception e) {
        if (e instanceof MySQLTimeoutException) {
            throw new SQLTimeOutException(e.getMessage(), e);
        } else if (e instanceof SQLException) {
            SQLException sqle = (SQLException) e;
            if (sqle.getNextException() instanceof SQLRecoverableException) {
                SQLRecoverableException sqlre = (SQLRecoverableException) sqle.getNextException();
                if (sqle.getErrorCode() == 17060 && sqlre.getErrorCode() == 17002) {
                    throw new SQLTimeOutException(sqlre.getMessage(), sqlre);
                }
            }
        }
        LoggerFactory.getLogger().error("[db-HeartBeatDao]", e);
    } finally {
        closeConn = System.currentTimeMillis();
        DBUtil.close(ps);
        DBUtil.close(conn);
        closeEndConn = System.currentTimeMillis();
    }

    String statTime = String.format(", beginConn: %d, ConUsed: %d, beginStmt: %d, stmtUsed: %d, closeConn: %d, closeUsed: %d",
            beginConn, endConn - beginConn, beginStmt, endStmt - beginStmt, closeConn, closeEndConn - closeConn);
    if (cnt == 1) {
        LoggerFactory.getLogger().info("[db-HeartBeatDao] 数据源: " + key + ", 插入心跳包成功. " + packet + statTime);
    } else {
        LoggerFactory.getLogger().error("[db-HeartBeatDao]: 数据源: " + key + ", 插入心跳包失败!" + packet + statTime);
    }
    return cnt;
}
 
Example #5
Source File: AutoMarkdownTest.java    From dal with Apache License 2.0 4 votes vote down vote up
private SQLException mockTimeoutException(){
	return new MySQLTimeoutException("Test mysql timeout excption");
}