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


Java SQLException.initCause方法代码示例

本文整理汇总了Java中java.sql.SQLException.initCause方法的典型用法代码示例。如果您正苦于以下问题:Java SQLException.initCause方法的具体用法?Java SQLException.initCause怎么用?Java SQLException.initCause使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.sql.SQLException的用法示例。


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

示例1: test04

import java.sql.SQLException; //导入方法依赖的package包/类
@Test
public void test04() {
    SQLException ex = new SerialException("Exception 1");
    ex.initCause(t1);
    SerialException ex1 = new SerialException("Exception 2");
    SerialException ex2 = new SerialException("Exception 3");
    ex2.initCause(t2);
    ex.setNextException(ex1);
    ex.setNextException(ex2);
    int num = 0;
    while (ex != null) {
        assertTrue(msgs[num++].equals(ex.getMessage()));
        Throwable c = ex.getCause();
        while (c != null) {
            assertTrue(msgs[num++].equals(c.getMessage()));
            c = c.getCause();
        }
        ex = ex.getNextException();
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:21,代码来源:SerialExceptionTests.java

示例2: test04

import java.sql.SQLException; //导入方法依赖的package包/类
@Test
public void test04() {
    SQLException ex = new SyncFactoryException("Exception 1");
    ex.initCause(t1);
    SyncFactoryException ex1 = new SyncFactoryException("Exception 2");
    SyncFactoryException ex2 = new SyncFactoryException("Exception 3");
    ex2.initCause(t2);
    ex.setNextException(ex1);
    ex.setNextException(ex2);
    int num = 0;
    while (ex != null) {
        assertTrue(msgs[num++].equals(ex.getMessage()));
        Throwable c = ex.getCause();
        while (c != null) {
            assertTrue(msgs[num++].equals(c.getMessage()));
            c = c.getCause();
        }
        ex = ex.getNextException();
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:21,代码来源:SyncFactoryExceptionTests.java

示例3: createSocketFactory

import java.sql.SQLException; //导入方法依赖的package包/类
private SocketFactory createSocketFactory() throws SQLException {
    try {
        if (this.socketFactoryClassName == null) {
            throw SQLError.createSQLException(Messages.getString("MysqlIO.75"), SQLError.SQL_STATE_UNABLE_TO_CONNECT_TO_DATASOURCE,
                    getExceptionInterceptor());
        }

        return (SocketFactory) (Class.forName(this.socketFactoryClassName).newInstance());
    } catch (Exception ex) {
        SQLException sqlEx = SQLError.createSQLException(Messages.getString("MysqlIO.76") + this.socketFactoryClassName + Messages.getString("MysqlIO.77"),
                SQLError.SQL_STATE_UNABLE_TO_CONNECT_TO_DATASOURCE, getExceptionInterceptor());

        sqlEx.initCause(ex);

        throw sqlEx;
    }
}
 
开发者ID:rafallis,项目名称:BibliotecaPS,代码行数:18,代码来源:MysqlIO.java

示例4: domSourceToString

import java.sql.SQLException; //导入方法依赖的package包/类
protected String domSourceToString() throws SQLException {
    try {
        DOMSource source = new DOMSource(this.asDOMResult.getNode());
        Transformer identity = TransformerFactory.newInstance().newTransformer();
        StringWriter stringOut = new StringWriter();
        Result result = new StreamResult(stringOut);
        identity.transform(source, result);

        return stringOut.toString();
    } catch (Throwable t) {
        SQLException sqlEx = SQLError.createSQLException(t.getMessage(), SQLError.SQL_STATE_ILLEGAL_ARGUMENT, this.exceptionInterceptor);
        sqlEx.initCause(t);

        throw sqlEx;
    }
}
 
开发者ID:Jugendhackt,项目名称:OpenVertretung,代码行数:17,代码来源:JDBC4MysqlSQLXML.java

示例5: init

import java.sql.SQLException; //导入方法依赖的package包/类
public void init(Connection conn, Properties props) throws SQLException {
    String regexFromUser = props.getProperty("resultSetScannerRegex");

    if (regexFromUser == null || regexFromUser.length() == 0) {
        throw new SQLException("resultSetScannerRegex must be configured, and must be > 0 characters");
    }

    try {
        this.regexP = Pattern.compile(regexFromUser);
    } catch (Throwable t) {
        SQLException sqlEx = new SQLException("Can't use configured regex due to underlying exception.");
        sqlEx.initCause(t);

        throw sqlEx;
    }

}
 
开发者ID:bragex,项目名称:the-vigilantes,代码行数:18,代码来源:ResultSetScannerInterceptor.java

示例6: getColumnCharacterEncoding

import java.sql.SQLException; //导入方法依赖的package包/类
/**
 * What's the Java character encoding name for the given column?
 * 
 * @param column
 *            the first column is 1, the second is 2, etc.
 * 
 * @return the Java character encoding name for the given column, or null if
 *         no Java character encoding maps to the MySQL character set for
 *         the given column.
 * 
 * @throws SQLException
 *             if an invalid column index is given.
 */
public String getColumnCharacterEncoding(int column) throws SQLException {
    String mysqlName = getColumnCharacterSet(column);

    String javaName = null;

    if (mysqlName != null) {
        try {
            javaName = CharsetMapping.getJavaEncodingForMysqlCharset(mysqlName);
        } catch (RuntimeException ex) {
            SQLException sqlEx = SQLError.createSQLException(ex.toString(), SQLError.SQL_STATE_ILLEGAL_ARGUMENT, null);
            sqlEx.initCause(ex);
            throw sqlEx;
        }
    }

    return javaName;
}
 
开发者ID:JuanJoseFJ,项目名称:ProyectoPacientes,代码行数:31,代码来源:ResultSetMetaData.java

示例7: setBytes

import java.sql.SQLException; //导入方法依赖的package包/类
/**
 * @see Blob#setBytes(long, byte[], int, int)
 */
public synchronized int setBytes(long writeAt, byte[] bytes, int offset, int length) throws SQLException {
    checkClosed();

    OutputStream bytesOut = setBinaryStream(writeAt);

    try {
        bytesOut.write(bytes, offset, length);
    } catch (IOException ioEx) {
        SQLException sqlEx = SQLError.createSQLException(Messages.getString("Blob.1"), SQLError.SQL_STATE_GENERAL_ERROR, this.exceptionInterceptor);
        sqlEx.initCause(ioEx);

        throw sqlEx;
    } finally {
        try {
            bytesOut.close();
        } catch (IOException doNothing) {
            // do nothing
        }
    }

    return length;
}
 
开发者ID:JuanJoseFJ,项目名称:ProyectoPacientes,代码行数:26,代码来源:Blob.java

示例8: createSQLException

import java.sql.SQLException; //导入方法依赖的package包/类
public static SQLException createSQLException(String message, String sqlState, Throwable cause, ExceptionInterceptor interceptor, Connection conn) {
    SQLException sqlEx = createSQLException(message, sqlState, null);
    if (sqlEx.getCause() == null) {
        sqlEx.initCause(cause);
    }
    // Run through the exception interceptor after setting the init cause.
    return runThroughExceptionInterceptor(interceptor, sqlEx, conn);
}
 
开发者ID:bragex,项目名称:the-vigilantes,代码行数:9,代码来源:SQLError.java

示例9: throwConnectionClosedException

import java.sql.SQLException; //导入方法依赖的package包/类
public void throwConnectionClosedException() throws SQLException {
    SQLException ex = SQLError.createSQLException("No operations allowed after connection closed.", SQLError.SQL_STATE_CONNECTION_NOT_OPEN,
            getExceptionInterceptor());

    if (this.forceClosedReason != null) {
        ex.initCause(this.forceClosedReason);
    }

    throw ex;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:11,代码来源:ConnectionImpl.java

示例10: connectOneTryOnly

import java.sql.SQLException; //导入方法依赖的package包/类
private void connectOneTryOnly(boolean isForReconnect, Properties mergedProps) throws SQLException {
    Exception connectionNotEstablishedBecause = null;

    try {

        coreConnect(mergedProps);
        this.connectionId = this.io.getThreadId();
        this.isClosed = false;

        // save state from old connection
        boolean oldAutoCommit = getAutoCommit();
        int oldIsolationLevel = this.isolationLevel;
        boolean oldReadOnly = isReadOnly(false);
        String oldCatalog = getCatalog();

        this.io.setStatementInterceptors(this.statementInterceptors);

        // Server properties might be different from previous connection, so initialize again...
        initializePropsFromServer();

        if (isForReconnect) {
            // Restore state from old connection
            setAutoCommit(oldAutoCommit);

            if (this.hasIsolationLevels) {
                setTransactionIsolation(oldIsolationLevel);
            }

            setCatalog(oldCatalog);

            setReadOnly(oldReadOnly);
        }
        return;

    } catch (Exception EEE) {

        if (EEE instanceof SQLException && ((SQLException) EEE).getErrorCode() == MysqlErrorNumbers.ER_MUST_CHANGE_PASSWORD
                && !getDisconnectOnExpiredPasswords()) {
            return;
        }

        if (this.io != null) {
            this.io.forceClose();
        }

        connectionNotEstablishedBecause = EEE;

        if (EEE instanceof SQLException) {
            throw (SQLException) EEE;
        }

        SQLException chainedEx = SQLError.createSQLException(Messages.getString("Connection.UnableToConnect"),
                SQLError.SQL_STATE_UNABLE_TO_CONNECT_TO_DATASOURCE, getExceptionInterceptor());
        chainedEx.initCause(connectionNotEstablishedBecause);

        throw chainedEx;
    }
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:59,代码来源:ConnectionImpl.java

示例11: createConnection

import java.sql.SQLException; //导入方法依赖的package包/类
/**
 * Creates a JDBC connection and tries to connect to the database.
 * @param now timestamp of when this was called
 * @param notUsed Argument not used
 * @return a PooledConnection that has been connected
 * @throws SQLException
 */
protected PooledConnection createConnection(long now, PooledConnection notUsed, String username, String password) throws SQLException {
    //no connections where available we'll create one
    PooledConnection con = create(false);
    if (username!=null) con.getAttributes().put(PooledConnection.PROP_USER, username);
    if (password!=null) con.getAttributes().put(PooledConnection.PROP_PASSWORD, password);
    boolean error = false;
    try {
        //connect and validate the connection
        con.lock();
        con.connect();
        if (con.validate(PooledConnection.VALIDATE_INIT)) {
            //no need to lock a new one, its not contented
            con.setTimestamp(now);
            if (getPoolProperties().isLogAbandoned()) {
                con.setStackTrace(getThreadDump());
            }
            if (!busy.offer(con)) {
                log.debug("Connection doesn't fit into busy array, connection will not be traceable.");
            }
            return con;
        } else {
            //validation failed, make sure we disconnect
            //and clean up
            throw new SQLException("Validation Query Failed, enable logValidationErrors for more details.");
        } //end if
    } catch (Exception e) {
        error = true;
        if (log.isDebugEnabled())
            log.debug("Unable to create a new JDBC connection.", e);
        if (e instanceof SQLException) {
            throw (SQLException)e;
        } else {
            SQLException ex = new SQLException(e.getMessage());
            ex.initCause(e);
            throw ex;
        }
    } finally {
        // con can never be null here
        if (error ) {
            release(con);
        }
        con.unlock();
    }//catch
}
 
开发者ID:sunmingshuai,项目名称:apache-tomcat-7.0.73-with-comment,代码行数:52,代码来源:ConnectionPool.java

示例12: resultInstantiation

import java.sql.SQLException; //导入方法依赖的package包/类
/**
 * Retrieves a new SQLXML result instantiation exception.
 *
 * @param cause of the exception.
 * @return a new SQLXML result instantiation exception
 */
static SQLException resultInstantiation(Throwable cause) {

    SQLException ex = Util.sqlException(ErrorCode.GENERAL_ERROR,
        "SQLXML Result instantiation failed: " + cause);

    ex.initCause(cause);

    return ex;
}
 
开发者ID:s-store,项目名称:sstore-soft,代码行数:16,代码来源:JDBCSQLXML.java

示例13: domInstantiation

import java.sql.SQLException; //导入方法依赖的package包/类
/**
 *  Retrieves a new SQLXML DOM instantiation exception.
 *
 * @param cause of the exception
 */
static SQLException domInstantiation(Throwable cause) {

    SQLException ex = Util.sqlException(ErrorCode.GENERAL_ERROR,
        "SQLXML DOM instantiation failed: " + cause);

    ex.initCause(cause);

    return ex;
}
 
开发者ID:s-store,项目名称:s-store,代码行数:15,代码来源:JDBCSQLXML.java


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