當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。