java.sql.SQLException.initCause()方法的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(6.8k)|赞(0)|评价(0)|浏览(154)

本文整理了Java中java.sql.SQLException.initCause()方法的一些代码示例,展示了SQLException.initCause()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。SQLException.initCause()方法的具体详情如下:
包路径:java.sql.SQLException
类名称:SQLException
方法名:initCause

SQLException.initCause介绍

暂无

代码示例

代码示例来源:origin: apache/activemq

/**
 * @see org.apache.activemq.store.jdbc.adapter.DefaultJDBCAdapter#getBinaryData(java.sql.ResultSet,
 *      int)
 */
@Override
protected byte[] getBinaryData(ResultSet rs, int index) throws SQLException {
  try (InputStream is = rs.getBinaryStream(index);
     ByteArrayOutputStream os = new ByteArrayOutputStream(1024 * 4)) {
    int ch;
    while ((ch = is.read()) >= 0) {
      os.write(ch);
    }
    return os.toByteArray();
  } catch (IOException e) {
    throw (SQLException)new SQLException("Error reading binary parameter: " + index).initCause(e);
  }
}

代码示例来源:origin: apache/geode

/**
 * Implementation of datasource function. This method is used to get the connection from the pool.
 * Default user name and password will be used.
 *
 * @return ???
 */
@Override
public Connection getConnection() throws SQLException {
 if (!isActive) {
  throw new SQLException(
    "GemFireTransactionDataSource::getConnection::No valid Connection available");
 }
 XAConnection xaConn = null;
 try {
  xaConn = (XAConnection) provider.borrowConnection();
  Connection conn = getSQLConnection(xaConn);
  registerTranxConnection(xaConn);
  return conn;
 } catch (Exception ex) {
  SQLException se = new SQLException(ex.getMessage());
  se.initCause(ex);
  throw se;
 }
}

代码示例来源:origin: nutzam/nutz

SQLException e2 = new SQLException();
e2.initCause(e.getCause());
throw e2;

代码示例来源:origin: pentaho/mondrian

firstException = new SQLException();
  firstException.initCause(t);
} catch (Throwable t) {
  if (firstException == null) {
    firstException = new SQLException();
    firstException.initCause(t);
} catch (Throwable t) {
  if (firstException == null) {
    firstException = new SQLException();
    firstException.initCause(t);

代码示例来源:origin: Meituan-Dianping/Zebra

/**
 * @see Blob#setBytes(long, byte[], int, int)
 */
@Override
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 = new SQLException("IO Error while writing bytes to blob");
    sqlEx.initCause(ioEx);
    throw sqlEx;
  } finally {
    try {
      bytesOut.close();
    } catch (IOException doNothing) {
      // do nothing
    }
  }
  return length;
}

代码示例来源:origin: geotools/geotools

SQLException e = new SQLException("Can't read the SQL script."); // TODO: localize
  e.initCause(exception); // TODO: inline cause when we will be allowed to target Java 6.
  throw e;
} finally {

代码示例来源:origin: camunda/camunda-bpm-platform

@Override
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
  try {
    return super.invoke(proxy, method, args);
  }catch (Exception t) {
    Throwable exception = t;
    if (t instanceof InvocationTargetException && t.getCause() != null) {
      exception = t.getCause();
      if (exception instanceof Error) {
        throw exception;
      }
    }
    Class<?> exceptionClass = exception.getClass();
    if (!isDeclaredException(method, exceptionClass)) {
      if (isDeclaredException(method,SQLException.class)) {
        SQLException sqlx = new SQLException("Uncaught underlying exception.");
        sqlx.initCause(exception);
        exception = sqlx;
      } else {
        RuntimeException rx = new RuntimeException("Uncaught underlying exception.");
        rx.initCause(exception);
        exception = rx;
      }
    }
    throw exception;
  }
}

代码示例来源:origin: geotools/geotools

forceReadOnly(directory);
} catch (IOException file) {
  throw (SQLException) new SQLException("Can't read the SQL script.").initCause(file);

代码示例来源:origin: geotools/geotools

new SQLException("Could not obtain native oracle connection.").initCause(e);
throw new SQLException("Could not obtain native oracle connection for " + cx.getClass());

代码示例来源:origin: geotools/geotools

} catch (IOException exception) {
  SQLException e =
      new SQLException(
          "Error occurred while executing "
              + "the EPSG database creation scripts");
  e.initCause(exception);
  throw e;
} finally {

代码示例来源:origin: geotools/geotools

/**
 * Set the data source for the EPSG database. If an other EPSG database was already in use, it
 * will be disconnected. Users should not invoke this method on the factory returned by {@link
 * ReferencingFactoryFinder}, since it could have a system-wide effect.
 *
 * @param datasource The new datasource.
 * @throws SQLException if an error occured.
 */
public synchronized void setDataSource(final DataSource datasource) throws SQLException {
  if (datasource != this.datasource) {
    try {
      dispose();
    } catch (FactoryException exception) {
      final Throwable cause = exception.getCause();
      if (cause instanceof SQLException) {
        throw (SQLException) cause;
      }
      if (cause instanceof RuntimeException) {
        throw (RuntimeException) cause;
      }
      // Not really an SQL exception, but we should not reach this point anyway.
      final SQLException e = new SQLException(exception.getLocalizedMessage());
      e.initCause(exception); // TODO: inline when we will be allowed to target Java 6.
      throw e;
    }
    this.datasource = datasource;
  }
}

代码示例来源:origin: geotools/geotools

SQLException e = new SQLException(Errors.format(ErrorKeys.CANT_READ_$1, ZIP_FILE));
e.initCause(

代码示例来源:origin: camunda/camunda-bpm-platform

throw new SQLException("Connection pool closed.");
    Thread.interrupted();
  SQLException sx = new SQLException("Pool wait interrupted.");
  sx.initCause(ex);
  throw sx;
} finally {

代码示例来源:origin: camunda/camunda-bpm-platform

log.debug("Unable to instantiate JDBC driver.", cn);
SQLException ex = new SQLException(cn.getMessage());
ex.initCause(cn);
throw ex;
  throw (SQLException)x;
} else {
  SQLException ex = new SQLException(x.getMessage());
  ex.initCause(x);
  throw ex;
throw new SQLException("Driver:"+driver+" returned null for URL:"+driverURL);

代码示例来源:origin: camunda/camunda-bpm-platform

SQLException sx = new SQLException("Unable to instantiate interceptor chain.");
    sx.initCause(x);
    throw sx;
SQLException s = new SQLException();
s.initCause(x);
throw s;

代码示例来源:origin: camunda/camunda-bpm-platform

throw (SQLException)e;
} else {
  SQLException ex = new SQLException(e.getMessage());
  ex.initCause(e);
  throw ex;

代码示例来源:origin: camunda/camunda-bpm-platform

throw (SQLException)x;
  } else {
    SQLException ex  = new SQLException(x.getMessage());
    ex.initCause(x);
    throw ex;
  throw new SQLException("Failed to validate a newly established connection.");
  throw (SQLException)x;
} else {
  SQLException ex  = new SQLException(x.getMessage());
  ex.initCause(x);
  throw ex;

代码示例来源:origin: com.eventsourcing/h2

/**
 * Convert an exception to a fulltext exception.
 *
 * @param e the original exception
 * @return the converted SQL exception
 */
protected static SQLException convertException(Exception e) {
  SQLException e2 = new SQLException(
      "Error while indexing document", "FULLTEXT");
  e2.initCause(e);
  return e2;
}

代码示例来源:origin: org.nuxeo.lib.core/nuxeo-core-storage-sql-extensions

private static SQLException convertException(String message, Exception e) {
  SQLException e2 = new SQLException(message);
  e2.initCause(e);
  return e2;
}

代码示例来源:origin: com.aoindustries/aocode-public

@Override
protected SQLException newException(String message, Throwable cause) {
  SQLException err=new SQLException(message);
  if(cause!=null) err.initCause(cause);
  return err;
}

相关文章