本文整理匯總了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();
}
}
示例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();
}
}
示例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;
}
}
示例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;
}
}
示例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;
}
}
示例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;
}
示例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;
}
示例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);
}
示例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;
}
示例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;
}
}
示例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
}
示例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;
}
示例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;
}