本文整理匯總了Java中java.sql.Clob.getCharacterStream方法的典型用法代碼示例。如果您正苦於以下問題:Java Clob.getCharacterStream方法的具體用法?Java Clob.getCharacterStream怎麽用?Java Clob.getCharacterStream使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.sql.Clob
的用法示例。
在下文中一共展示了Clob.getCharacterStream方法的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: testClobTruncate
import java.sql.Clob; //導入方法依賴的package包/類
/**
* Tests for fix to BUG#1130
*
* @throws Exception
* if the test fails
*/
public void testClobTruncate() throws Exception {
createTable("testClobTruncate", "(field1 TEXT)");
this.stmt.executeUpdate("INSERT INTO testClobTruncate VALUES ('abcdefg')");
this.rs = this.stmt.executeQuery("SELECT * FROM testClobTruncate");
this.rs.next();
Clob clob = this.rs.getClob(1);
clob.truncate(3);
Reader reader = clob.getCharacterStream();
char[] buf = new char[8];
int charsRead = reader.read(buf);
String clobAsString = new String(buf, 0, charsRead);
assertTrue(clobAsString.equals("abc"));
}
示例2: 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;
}
}
}
}
示例3: toStr
import java.sql.Clob; //導入方法依賴的package包/類
public static String toStr(Clob clob) {
StringBuffer sb = new StringBuffer();
try {
java.io.Reader is = clob.getCharacterStream();
BufferedReader br = new BufferedReader(is);
String s = br.readLine();
while (s != null) {
sb.append(s);
s = br.readLine();
}
} catch (Exception e) {
throw new RuntimeException(e);
}
return sb.toString();
}
示例4: write
import java.sql.Clob; //導入方法依賴的package包/類
public void write(JSONSerializer serializer, Object object, Object fieldName, Type fieldType, int features) throws IOException {
try {
if (object == null) {
serializer.writeNull();
return;
}
Clob clob = (Clob) object;
Reader reader = clob.getCharacterStream();
StringWriter writer = new StringWriter();
char[] buf = new char[1024];
int len = 0;
while ((len = reader.read(buf)) != -1) {
writer.write(buf, 0, len);
}
reader.close();
String text = writer.toString();
serializer.write(text);
} catch (SQLException e) {
throw new IOException("write clob error", e);
}
}
示例5: 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);
setType(binding, MysqlDefs.FIELD_TYPE_BLOB);
binding.value = x.getCharacterStream();
binding.isNull = false;
binding.isLongData = true;
if (this.connection.getUseStreamLengthsInPrepStmts()) {
binding.bindLength = x.length();
} else {
binding.bindLength = -1;
}
}
}
}
示例6: write
import java.sql.Clob; //導入方法依賴的package包/類
public void write(JSONSerializer serializer, Object object, Object fieldName, Type fieldType, int features) throws IOException {
try {
if (object == null) {
serializer.writeNull();
return;
}
Clob clob = (Clob) object;
Reader reader = clob.getCharacterStream();
StringBuilder buf = new StringBuilder();
try {
char[] chars = new char[2048];
for (;;) {
int len = reader.read(chars, 0, chars.length);
if (len < 0) {
break;
}
buf.append(chars, 0, len);
}
} catch(Exception ex) {
throw new JSONException("read string from reader error", ex);
}
String text = buf.toString();
reader.close();
serializer.write(text);
} catch (SQLException e) {
throw new IOException("write clob error", e);
}
}
示例7: 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());
}
}
示例8: 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();
}
示例9: getClobAsCharacterStream
import java.sql.Clob; //導入方法依賴的package包/類
@Override
public Reader getClobAsCharacterStream(ResultSet rs, int columnIndex) throws SQLException {
logger.debug("Returning Oracle CLOB as character stream");
Clob clob = rs.getClob(columnIndex);
initializeResourcesBeforeRead(rs.getStatement().getConnection(), clob);
Reader retVal = (clob != null ? clob.getCharacterStream() : null);
releaseResourcesAfterRead(rs.getStatement().getConnection(), clob);
return retVal;
}
示例10: 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;
}
final long length = x.length();
if (length > Integer.MAX_VALUE) {
String msg = "Max Clob input character length exceeded: " + length; // NOI18N
throw JDBCUtil.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 (Throwable e) {
throw JDBCUtil.sqlException(ErrorCode.SERVER_TRANSFER_CORRUPTED,
e.toString(), e);
}
}
示例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());
}
示例12: 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()));
}
}