本文整理汇总了Java中java.sql.Clob.getSubString方法的典型用法代码示例。如果您正苦于以下问题:Java Clob.getSubString方法的具体用法?Java Clob.getSubString怎么用?Java Clob.getSubString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.sql.Clob
的用法示例。
在下文中一共展示了Clob.getSubString方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: clobToString
import java.sql.Clob; //导入方法依赖的package包/类
public static String clobToString(Clob clobValue) {
StringBuilder contentPart = new StringBuilder();
try {
long size = clobValue.length();
long retrievalCount = Math.min(size, 255);
String sampleContent = clobValue.getSubString(1, (int) retrievalCount);
contentPart.append(sampleContent.replaceAll("[\n\r]+", " "));//NOI18N
if (size > 255) {
contentPart.append(" [...]"); //NOI18N
}
return contentPart.toString();
} catch (SQLException ex) {
LOG.log(Level.INFO,
"Failed to retrieve CLOB content", //NOI18N
ex);
return clobToDescription(clobValue);
}
}
示例2: getClobAsString
import java.sql.Clob; //导入方法依赖的package包/类
@Override
public String getClobAsString(ResultSet rs, int columnIndex) throws SQLException {
logger.debug("Returning Oracle CLOB as string");
Clob clob = rs.getClob(columnIndex);
initializeResourcesBeforeRead(rs.getStatement().getConnection(), clob);
String retVal = (clob != null ? clob.getSubString(1, (int) clob.length()) : null);
releaseResourcesAfterRead(rs.getStatement().getConnection(), clob);
return retVal;
}
示例3: getClobAsString
import java.sql.Clob; //导入方法依赖的package包/类
@Override
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);
}
}
示例4: position
import java.sql.Clob; //导入方法依赖的package包/类
/**
* Retrieves the character position at which the specified
* <code>Clob</code> object <code>searchstr</code> appears in this
* <code>Clob</code> object. The search begins at position
* <code>start</code>.
*
* @param searchstr the <code>Clob</code> object for which to search
* @param start the position at which to begin searching; the first
* position is 1
* @return the position at which the <code>Clob</code> object appears
* or -1 if it is not present; the first position is 1
* @exception SQLException if there is an error accessing the
* <code>CLOB</code> value
*
* @since JDK 1.2, HSQLDB 1.7.2
*/
public long position(final Clob searchstr,
long start) throws SQLException {
if (searchstr == null) {
return -1;
}
final String ldata = data;
final long dlen = ldata.length();
final long sslen = searchstr.length();
// This is potentially much less expensive than materializing a large
// substring from some other vendor's CLOB. Indeed, we should probably
// do the comparison piecewise, using an in-memory buffer (or temp-files
// when available), if it is detected that the input CLOB is very long.
if (start > dlen - sslen) {
return -1;
}
// by now, we know sslen and start are both < Integer.MAX_VALUE
String s;
if (searchstr instanceof jdbcClob) {
s = ((jdbcClob) searchstr).data;
} else {
s = searchstr.getSubString(1L, (int) sslen);
}
final int pos = ldata.indexOf(s, (int) start);
return (pos < 0) ? -1
: pos + 1;
}
示例5: position
import java.sql.Clob; //导入方法依赖的package包/类
/**
* Retrieves the character position at which the specified
* <code>Clob</code> object <code>searchstr</code> appears in this
* <code>Clob</code> object. The search begins at position
* <code>start</code>.
*
* @param searchstr the <code>Clob</code> object for which to search
* @param start the position at which to begin searching; the first
* position is 1
* @return the position at which the <code>Clob</code> object appears
* or -1 if it is not present; the first position is 1
* @exception SQLException if there is an error accessing the
* <code>CLOB</code> value
*
* @since JDK 1.2, HSQLDB 1.7.2
*/
public long position(final Clob searchstr,
long start) throws SQLException {
if (searchstr == null) {
return -1;
}
final String ldata = data;
final long dlen = ldata.length();
final long sslen = searchstr.length();
start--; //***** FOIRGOT THIS *******
// This is potentially much less expensive than materializing a large
// substring from some other vendor's CLOB. Indeed, we should probably
// do the comparison piecewise, using an in-memory buffer (or temp-files
// when available), if it is detected that the input CLOB is very long.
if (start > dlen - sslen) {
return -1;
}
// by now, we know sslen and start are both < Integer.MAX_VALUE
String s;
if (searchstr instanceof jdbcClob) {
s = ((jdbcClob) searchstr).data;
} else {
s = searchstr.getSubString(1L, (int) sslen);
}
final int pos = ldata.indexOf(s, (int) start);
return (pos < 0) ? -1
: pos + 1;
}
示例6: getNullableResult
import java.sql.Clob; //导入方法依赖的package包/类
@Override
public String getNullableResult(ResultSet rs, String columnName) throws SQLException {
String value = "";
Clob clob = rs.getClob(columnName);
if (clob != null) {
int size = (int) clob.length();
value = clob.getSubString(1, size);
}
return value;
}
示例7: position
import java.sql.Clob; //导入方法依赖的package包/类
/**
* Retrieves the character position at which the specified
* <code>Clob</code> object <code>searchstr</code> appears in this
* <code>Clob</code> object. The search begins at position
* <code>start</code>.
*
* @param searchstr the <code>Clob</code> object for which to search
* @param start the position at which to begin searching; the first
* position is 1
* @return the position at which the <code>Clob</code> object appears
* or -1 if it is not present; the first position is 1
* @exception SQLException if there is an error accessing the
* <code>CLOB</code> value or if start is less than 1
* @exception SQLFeatureNotSupportedException if the JDBC driver does not support
* this method
* @since JDK 1.2, HSQLDB 1.7.2
*/
public long position(final Clob searchstr,
long start) throws SQLException {
final String ldata = data;
checkValid(ldata);
if (start < MIN_POS) {
throw Util.outOfRangeArgument("start: " + start);
}
if (searchstr == null) {
return -1;
}
final long dlen = ldata.length();
final long sslen = searchstr.length();
start--;
// This is potentially much less expensive than materializing a large
// substring from some other vendor's CLOB. Indeed, we should probably
// do the comparison piecewise, using an in-memory buffer (or temp-files
// when available), if it is detected that the input CLOB is very long.
if (start > dlen - sslen) {
return -1;
}
// by now, we know sslen and start are both < Integer.MAX_VALUE
String s;
if (searchstr instanceof JDBCClob) {
s = ((JDBCClob) searchstr).data();
} else {
s = searchstr.getSubString(1L, (int) sslen);
}
final int pos = ldata.indexOf(s, (int) start);
return (pos < 0) ? -1
: pos + 1;
}
示例8: readClobRef
import java.sql.Clob; //导入方法依赖的package包/类
/**
* Actually read a ClobRef instance from the ResultSet and materialize
* the data either inline or to a file.
*
* @param colNum the column of the ResultSet's current row to read.
* @param r the ResultSet to read from.
* @return a ClobRef encapsulating the data in this field.
* @throws IOException if an error occurs writing to the FileSystem.
* @throws SQLException if an error occurs reading from the database.
*/
public com.cloudera.sqoop.lib.ClobRef readClobRef(int colNum, ResultSet r)
throws IOException, InterruptedException, SQLException {
long maxInlineLobLen = conf.getLong(
MAX_INLINE_LOB_LEN_KEY,
DEFAULT_MAX_LOB_LENGTH);
Clob c = r.getClob(colNum);
if (null == c) {
return null;
} else if (c.length() > maxInlineLobLen) {
// Deserialize large CLOB into separate file.
long len = c.length();
LobFile.Writer lobWriter = getClobWriter();
long recordOffset = lobWriter.tell();
Reader reader = null;
Writer w = lobWriter.writeClobRecord(len);
try {
reader = c.getCharacterStream();
copyAll(reader, w);
} finally {
if (null != w) {
w.close();
}
if (null != reader) {
reader.close();
}
// Mark the record as finished.
lobWriter.finishRecord();
}
return new com.cloudera.sqoop.lib.ClobRef(
getRelativePath(lobWriter), recordOffset, len);
} else {
// This is a 1-based array.
return new com.cloudera.sqoop.lib.ClobRef(
c.getSubString(1, (int) c.length()));
}
}
示例9: clob2String
import java.sql.Clob; //导入方法依赖的package包/类
private static String clob2String(Clob clob) throws Exception {
return (clob != null ? clob.getSubString(1, (int) clob.length()) : null);
}