本文整理汇总了Java中java.sql.Clob.length方法的典型用法代码示例。如果您正苦于以下问题:Java Clob.length方法的具体用法?Java Clob.length怎么用?Java Clob.length使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.sql.Clob
的用法示例。
在下文中一共展示了Clob.length方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: clobToDescription
import java.sql.Clob; //导入方法依赖的package包/类
public static String clobToDescription(Clob clobValue) {
StringBuilder clobDescription = new StringBuilder("<CLOB "); //NOI18N
try {
long size = clobValue.length();
if (size < 1000) {
clobDescription.append(String.format("%1$d Chars", size)); //NOI18N
} else if (size < 1000000) {
clobDescription.append(String.format("%1$d kChars", size / 1000)); //NOI18N
} else {
clobDescription.append(String.format("%1$d MChars", size
/ 1000000)); //NOI18N
}
} catch (SQLException ex) {
clobDescription.append("of unknown size"); //NOI18N
}
clobDescription.append(">");
return clobDescription.toString();
}
示例3: setClob
import java.sql.Clob; //导入方法依赖的package包/类
/**
* @see java.sql.PreparedStatement#setClob(int, java.sql.Clob)
*/
@Override
public void setClob(int parameterIndex, Clob x) throws SQLException {
synchronized (checkClosed().getConnectionMutex()) {
if (x == null) {
setNull(parameterIndex, java.sql.Types.BINARY);
} else {
BindValue binding = getBinding(parameterIndex, true);
resetToType(binding, MysqlDefs.FIELD_TYPE_BLOB);
binding.value = x.getCharacterStream();
binding.isLongData = true;
if (this.connection.getUseStreamLengthsInPrepStmts()) {
binding.bindLength = x.length();
} else {
binding.bindLength = -1;
}
}
}
}
示例4: PreparedStmtSetValue
import java.sql.Clob; //导入方法依赖的package包/类
public static Object PreparedStmtSetValue(int columnType, ResultSet rs, int index) throws SQLException, IOException{
StringBuffer sb = new StringBuffer();
switch(columnType){
case 2005: //CLOB
Clob clob = rs.getClob(index);
if (clob == null){
return null;
}
Reader reader = clob.getCharacterStream();
char[] buffer = new char[(int)clob.length()];
while(reader.read(buffer) != -1){
sb.append(buffer);
}
return sb.toString();
case 2004: //BLOB
Blob blob = rs.getBlob(index);
if (blob == null){
return null;
}
InputStream in = blob.getBinaryStream();
byte[] Bytebuffer = new byte[(int)blob.length()];
in.read(Bytebuffer);
return Bytebuffer;
case -2:
return rs.getBytes(index);
default:
return rs.getObject(index);
}
}
示例5: 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;
}
示例6: setClobForStringParameter
import java.sql.Clob; //导入方法依赖的package包/类
private void setClobForStringParameter(int parameterIndex,
Clob x) throws SQLException {
if (x instanceof JDBCClob) {
setParameter(parameterIndex, ((JDBCClob) x).data());
return;
} else if (x == null) {
setParameter(parameterIndex, null);
return;
}
checkSetParameterIndex(parameterIndex, false);
final long length = x.length();
if (length > Integer.MAX_VALUE) {
String msg = "Max Clob input character length exceeded: " + length; // NOI18N
throw Util.sqlException(ErrorCode.JDBC_INPUTSTREAM_ERROR, msg);
}
try {
java.io.Reader reader = x.getCharacterStream();
CharArrayWriter writer = new CharArrayWriter(reader, (int) length);
setParameter(parameterIndex, writer.toString());
} catch (IOException e) {
throw Util.sqlException(ErrorCode.SERVER_TRANSFER_CORRUPTED,
e.toString());
}
}
示例7: ConvertClobToString
import java.sql.Clob; //导入方法依赖的package包/类
public static String ConvertClobToString(StringBuffer sb, Clob clob) throws SQLException, IOException{
Reader reader = clob.getCharacterStream();
char[] buffer = new char[(int)clob.length()];
while(reader.read(buffer) != -1){
sb.append(buffer);
}
return sb.toString();
}
示例8: 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;
}
示例9: 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;
}
示例10: 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;
}
示例11: setClob
import java.sql.Clob; //导入方法依赖的package包/类
/**
* <!-- start generic documentation -->
* Sets the designated parameter to the given <code>Clob</code> object.
* The driver converts this to an SQL <code>CLOB</code> value when it
* sends it to the database. <p>
* <!-- end generic documentation -->
*
* <!-- start release-specific documentation -->
* <div class="ReleaseSpecificDocumentation">
* <h3>HSQLDB-Specific Information:</h3> <p>
*
* Previous to 1.7.2, this feature was not supported. <p>
*
* Since 1.7.2, setClob is supported. With 1.7.2, setting Blob objects is
* limited to those of length less than or equal to Integer.MAX_VALUE.
* In 1.7.2, setClob(i,x) is rougly equivalent (null and length handling
* not shown) to: <p>
*
* <pre class="JavaCodeExample">
* <b>setCharacterStream</b>(i, x.<b>getCharacterStream</b>(), (<span class="JavaKeyWord">int</span>) x.<b>length</b>());
* </pre></div>
* <!-- end release-specific documentation -->
* @param i the first parameter is 1, the second is 2, ...
* @param x a <code>Clob</code> object that maps an SQL <code>CLOB</code>
* value
* @exception SQLException if a database access error occurs
* @since JDK 1.2 (JDK 1.1.x developers: read the new overview for
* jdbcPreparedStatement)
*/
// [email protected] 20030801 - method implemented
//#ifdef JAVA2
public void setClob(int i, Clob x) throws SQLException {
if (x instanceof jdbcClob) {
setParameter(i, ((jdbcClob) x).data);
return;
} else if (x == null) {
setParameter(i, null);
return;
}
checkSetParameterIndex(i, false);
final long length = x.length();
if (length > Integer.MAX_VALUE) {
String msg = "Max Clob input character length exceeded: " + length;
throw Util.sqlException(Trace.INPUTSTREAM_ERROR, msg);
}
java.io.Reader reader = x.getCharacterStream();
final StringBuffer sb = new StringBuffer();
final int size = 2048;
final char[] buff = new char[size];
try {
for (int left = (int) length; left > 0; ) {
final int read = reader.read(buff, 0, left > size ? size
: left);
if (read == -1) {
break;
}
sb.append(buff, 0, read);
left -= read;
}
} catch (IOException e) {
throw Util.sqlException(Trace.TRANSFER_CORRUPTED, e.toString());
}
setParameter(i, sb.toString());
}