java.sql.Clob类的使用及代码示例

x33g5p2x  于2022-01-18 转载在 其他  
字(8.6k)|赞(0)|评价(0)|浏览(376)

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

Clob介绍

[英]A Java interface mapping for the SQL CLOB type.

An SQL CLOB type stores a large array of characters as the value in a column of a database.

The java.sql.Clob interface provides methods for setting and retrieving data in the Clob, for querying Clob data length, for searching for data within the Clob.
[中]SQL CLOB类型的Java接口映射。
SQL CLOB类型将大量字符作为值存储在数据库的列中。
爪哇。sql。Clob接口提供了在Clob中设置和检索数据、查询Clob数据长度以及在Clob中搜索数据的方法。

代码示例

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

public String handleClob(Clob clob) throws SQLException {
  if (clob == null)
    return null;
  
  Reader reader = null;
  try {
    reader = clob.getCharacterStream();
    if (reader == null)
      return null;
    char[] buffer = new char[(int)clob.length()];
    if (buffer.length == 0)
      return null;
    reader.read(buffer);
    return new String(buffer);
  } catch (IOException e) {
    throw new RuntimeException(e);
  }
  finally {
    if (reader != null)
      try {reader.close();} catch (IOException e) {throw new RuntimeException(e);}
  }
}

代码示例来源:origin: spring-projects/spring-framework

Object obj = rs.getObject(index);
String className = null;
if (obj != null) {
  obj = blob.getBytes(1, (int) blob.length());
  obj = clob.getSubString(1, (int) clob.length());
  obj = rs.getTimestamp(index);
  String metaDataClassName = rs.getMetaData().getColumnClassName(index);
  if ("java.sql.Timestamp".equals(metaDataClassName) || "oracle.sql.TIMESTAMP".equals(metaDataClassName)) {
    obj = rs.getTimestamp(index);

代码示例来源:origin: spring-projects/spring-framework

@Override
public InputStream getClobAsAsciiStream(ResultSet rs, int columnIndex) throws SQLException {
  logger.debug("Returning CLOB as ASCII stream");
  if (this.wrapAsLob) {
    Clob clob = rs.getClob(columnIndex);
    return clob.getAsciiStream();
  }
  else {
    return rs.getAsciiStream(columnIndex);
  }
}

代码示例来源:origin: alibaba/druid

public String getClobAsString(ResultSet rs, int columnIndex) throws SQLException {
  Clob clob = rs.getClob(columnIndex);
  if (clob == null) {
    return null;
  }
  return clob.getSubString(1, (int) clob.length());
}

代码示例来源:origin: spring-projects/spring-framework

@Override
@Nullable
public String getClobAsString(ResultSet rs, int columnIndex) throws SQLException {
  logger.debug("Returning CLOB as string");
  if (this.wrapAsLob) {
    Clob clob = rs.getClob(columnIndex);
    return clob.getSubString(1, (int) clob.length());
  }
  else {
    return rs.getString(columnIndex);
  }
}

代码示例来源:origin: apache/incubator-gobblin

private String readClobAsString(Clob logClob) throws SQLException {
 if (logClob == null) {
  return StringUtils.EMPTY;
 }
 long length = logClob.length();
 return logClob.getSubString(1, (int) length);
}

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

ResultSetMetaData rsmd = rs.getMetaData();
int numColumns = rsmd.getColumnCount();
String[] columnNames = new String[numColumns];
while (rs.next()) {
      l = rs.getInt(i + 1);
      if (rs.wasNull()) {
        jgen.writeNull();
      Blob blob = rs.getBlob(i);
      provider.defaultSerializeValue(blob.getBinaryStream(), jgen);
      blob.free();
      break;
      Clob clob = rs.getClob(i);
      provider.defaultSerializeValue(clob.getCharacterStream(), jgen);
      clob.free();
      break;

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

dataFileWriter.create(schema, outStream);
      Clob clob = rs.getClob(i);
      if (clob != null) {
        long numChars = clob.length();
        char[] buffer = new char[(int) numChars];
        InputStream is = clob.getAsciiStream();
        int index = 0;
        int c = is.read();
        clob.free();
      } else {
        rec.put(i - 1, null);
        long numChars = (int) nClob.length();
        final CharBuffer buffer = CharBuffer.allocate((int) numChars);
        characterStream.read(buffer);
        buffer.flip();
        rec.put(i - 1, buffer.toString());
        blob.free();
      } else {
        rec.put(i - 1, null);

代码示例来源:origin: copper-engine/copper-engine

@Override
public String queryAuditTrailMessage(long id, Connection con) throws SQLException  {
  final StringBuilder sql = new StringBuilder();
  sql.append("SELECT LONG_MESSAGE FROM COP_AUDIT_TRAIL_EVENT WHERE SEQ_ID = ?");
  try (PreparedStatement pStmtQueryWFIs = con.prepareStatement(sql.toString())) {
    pStmtQueryWFIs.setObject(1, id);
    ResultSet rs = pStmtQueryWFIs.executeQuery();
    while (rs.next()) {
      try {
        Clob message = rs.getClob("LONG_MESSAGE");
        if ((int) message.length() > 0) {
          return message.getSubString(1, (int) message.length());
        }
        return null;
      } catch (Exception e) {
        logger.error("decoding of '" + rs + "' failed: " + e.toString(), e);
      }
    }
  }
  return null;
}

代码示例来源:origin: org.copper-engine/copper-monitoring-server

@Override
public String selectAuditTrailMessage(long id, Connection con) {
  PreparedStatement selectStmt = null;
  try {
    selectStmt = con.prepareStatement("SELECT LONG_MESSAGE FROM COP_AUDIT_TRAIL_EVENT WHERE SEQ_ID=?");
    selectStmt.setLong(1, id);
    ResultSet result = selectStmt.executeQuery();
    while (result.next()) {
      Clob message = result.getClob(1);
      if ((int) message.length() > 0) {
        return messagePostProcessor.deserialize(message.getSubString(1, (int) message.length()));
      }
    }
    result.close();
  } catch (SQLException e) {
    throw new RuntimeException(e);
  } finally {
    JdbcUtils.closeStatement(selectStmt);
  }
  return "";
}

代码示例来源:origin: org.postgresql/postgresql

Reader l_inStream = x.getCharacterStream();
int l_length = (int) x.length();
LargeObjectManager lom = connection.getLargeObjectAPI();
long oid = lom.createLO();
 int c = l_inStream.read();
 int p = 0;
 while (c > -1 && p < l_length) {
  lw.write(c);
  c = l_inStream.read();
  p++;

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

reader = (Reader) data;
} else {
  reader = ((Clob) data).getCharacterStream();
Integer wId;
while((wId = setting.getWordId(word)) == null) {
  prepInsertWord.setString(1, word);
  prepInsertWord.execute();
  ResultSet rs = prepInsertWord.getGeneratedKeys();
  if (rs.next()) {
    wordId = rs.getInt(1);
    if (wordId != 0) {
      setting.addWord(word, wordId);

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

private OpResult executeUpdate(Connection connection, String query, String key, String value) throws SQLException {
  OpResult result = new OpResult();
  PreparedStatement statement = null;
  try {
    statement = connection.prepareStatement(query);
    Clob clob = connection.createClob();
    clob.setString(1, value);
    statement.setClob(1, clob);
    statement.setString(2, key);
    int status = statement.executeUpdate();
    LOG.info("update {} with query={}", status, query);
  } finally {
    if (statement != null) {
      statement.close();
    }
  }
  return result;
}

代码示例来源:origin: davidmoten/rxjava-jdbc

@Override
public void close() throws IOException {
  try {
    reader.close();
  } finally {
    try {
      clob.free();
    } catch (SQLException e) {
      log.debug(e.getMessage());
    }
  }
}

代码示例来源:origin: com.alibaba/fastjson

Reader reader = clob.getCharacterStream();
    char[] chars = new char[2048];
    for (;;) {
      int len = reader.read(chars, 0, chars.length);
      if (len < 0) {
        break;
  reader.close();
  serializer.write(text);
} catch (SQLException e) {

代码示例来源:origin: SonarSource/sonarqube

private static List<Map<String, Object>> getHashMap(ResultSet resultSet) throws Exception {
 ResultSetMetaData metaData = resultSet.getMetaData();
 int colCount = metaData.getColumnCount();
 List<Map<String, Object>> rows = newArrayList();
 while (resultSet.next()) {
  Map<String, Object> columns = newHashMap();
  for (int i = 1; i <= colCount; i++) {
   Object value = resultSet.getObject(i);
   if (value instanceof Clob) {
    Clob clob = (Clob) value;
    value = IOUtils.toString((clob.getAsciiStream()));
    doClobFree(clob);
   } else if (value instanceof BigDecimal) {

代码示例来源:origin: davidmoten/rxjava-jdbc

private static <T> Object getObject(final ResultSet rs, Class<T> cls, int i) {
  try {
    if (rs.getObject(i) == null) {
      return null;
    final int type = rs.getMetaData().getColumnType(i);
      return rs.getDate(i, Calendar.getInstance());
    else if (type == Types.TIME)
      return rs.getTime(i, Calendar.getInstance());
    } else if (type == Types.CLOB && Reader.class.isAssignableFrom(cls)) {
      Clob c = rs.getClob(i);
      Reader r = c.getCharacterStream();
      return createFreeOnCloseReader(c, r);
    } else if (type == Types.BLOB && cls.equals(byte[].class)) {
    } else if (type == Types.BLOB && InputStream.class.isAssignableFrom(cls)) {
      final Blob b = rs.getBlob(i);
      final InputStream is = rs.getBlob(i).getBinaryStream();
      return createFreeOnCloseInputStream(b, is);
    } else

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

public static String getString(Clob data) throws SQLException {

  StringBuilder sb = new StringBuilder();
  char[] cbuf = new char[8192];
  int l = 0;
  try (Reader r = data.getCharacterStream()) {
    while ((l = r.read(cbuf)) > -1) {
      sb.append(cbuf, 0, l);
    }
  } catch (IOException ioe) {
    throw new SQLException("Unable to read character stream from Clob.", ioe);
  }
  return sb.toString();
}

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

wkt = rs.getString(column + "_inline");
} catch (SQLException e) {
for (int i = 0; i < rs.getMetaData().getColumnCount(); i++) {
  if (column.equals(rs.getMetaData().getColumnName(i + 1))) {
    index = i + 1;
    break;
  return null;
InputStream in = clob.getAsciiStream();
try {
  return new WKTReader(factory).read(new InputStreamReader(in));

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

java.sql.Connection con;
javax.xml.bind.Marshaller marshaller;

Clob xmlClob = con.createClob();
try {
 try (Writer xmlClobWriter = xmlClob.setCharacterStream(1)) {
  m.marshal(jaxbObject, xmlClobWriter);
 } // xmlClobWriter.close();
 try (PreparedStatement stmt = con.prepareStatement("INSERT INTO table (xml) values(?)")) {
  stmt.setClob(1, xmlClob);
  stmt.executeUpdate();
 }
} finally {
 xmlClob.free();
}

相关文章