oracle.sql.BLOB.trim()方法的使用及代码示例

x33g5p2x  于2022-01-17 转载在 其他  
字(3.4k)|赞(0)|评价(0)|浏览(171)

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

BLOB.trim介绍

暂无

代码示例

代码示例来源:origin: quartz-scheduler/quartz

@SuppressWarnings("deprecation")
  protected Blob writeDataToBlob(ResultSet rs, int column, byte[] data) throws SQLException {

    Blob blob = rs.getBlob(column); // get blob

    if (blob == null) { 
      throw new SQLException("Driver's Blob representation is null!");
    }
    
    if (blob instanceof oracle.sql.BLOB) { // is it an oracle blob?
      ((oracle.sql.BLOB) blob).putBytes(1, data);
      ((oracle.sql.BLOB) blob).trim(data.length);
      return blob;
    } else {
      throw new SQLException(
          "Driver's Blob representation is of an unsupported type: "
              + blob.getClass().getName());
    }
  }
}

代码示例来源:origin: quartz-scheduler/quartz

@SuppressWarnings("deprecation")
  protected Blob writeDataToBlob(ResultSet rs, int column, byte[] data) throws SQLException {

    Blob blob = rs.getBlob(column); // get blob

    if (blob == null) { 
      throw new SQLException("Driver's Blob representation is null!");
    }
    
    if (blob instanceof oracle.sql.BLOB) { // is it an oracle blob?
      ((oracle.sql.BLOB) blob).putBytes(1, data);
      ((oracle.sql.BLOB) blob).trim(data.length);
      return blob;
    } else {
      throw new SQLException(
          "Driver's Blob representation is of an unsupported type: "
              + blob.getClass().getName());
    }
  }
}

代码示例来源:origin: org.quartz-scheduler/quartz-oracle

@SuppressWarnings("deprecation")
  protected Blob writeDataToBlob(ResultSet rs, int column, byte[] data) throws SQLException {

    Blob blob = rs.getBlob(column); // get blob

    if (blob == null) { 
      throw new SQLException("Driver's Blob representation is null!");
    }
    
    if (blob instanceof oracle.sql.BLOB) { // is it an oracle blob?
      ((oracle.sql.BLOB) blob).putBytes(1, data);
      ((oracle.sql.BLOB) blob).trim(data.length);
      return blob;
    } else {
      throw new SQLException(
          "Driver's Blob representation is of an unsupported type: "
              + blob.getClass().getName());
    }
  }
}

代码示例来源:origin: stackoverflow.com

int primaryKeyId = getNextPrimaryKeyId();
PreparedStatement stmt1 = conn.prepareStatement(" insert into docTable values (?, ?, empty_blob()) ");
stmt1.setInt(1, primaryKeyId );
stmt1.setString(2, getDocumentTitle());
stmt1.executeUpdate();

PreparedStatement stmt2 = conn.prepareStatement(" select doc from docTable where id = ? for update ");
stmt2.setInt(1, primaryKeyId);
stmt2.execute();

OracleResultSet rset = (OracleResultSet)stmt2.getResultSet();
if (rset.next()) {
 BLOB document = rset.getBLOB("doc");
 document.trim(0);
 OutputStream os = document.getBinaryOutputStream();
 os.write(getDocumentToBeWrittenToDb());
 os.flush;
 os.close;
}

代码示例来源:origin: org.opencms/opencms-solr

/**
 * Generates an Output stream that writes to a blob, also truncating the existing blob if required.<p>
 * 
 * Apparently Oracle requires some non-standard handling here.<p>
 * 
 * @param res the result set where the blob is located in 
 * @param name the name of the database column where the blob is located
 * @return an Output stream from a blob
 * @throws SQLException if something goes wring
 */
public static OutputStream getOutputStreamFromBlob(ResultSet res, String name) throws SQLException {
  // TODO: perform blob check only once and store Oracle version in a static private member 
  // TODO: best do this during system startup / db init phase once
  Blob blob = res.getBlob(name);
  try {
    // jdbc standard
    blob.truncate(0);
    return blob.setBinaryStream(0L);
  } catch (SQLException e) {
    // oracle 9 & 8 (if using the same jdbc driver as provided by oracle9: ojdbc14.jar)
    ((oracle.sql.BLOB)blob).trim(0);
    return ((oracle.sql.BLOB)blob).getBinaryOutputStream();
  }
}

相关文章