包可用: public static void setLargeTextField(PreparedStatement pstmt,
int parameterIndex, String value) throws SQLException
{
Reader bodyReader = null;
try {
bodyReader = new StringReader(value);
pstmt.setCharacterStream(parameterIndex, bodyReader, value.length());
}
catch (Exception e) {
e.printStackTrace();
throw new SQLException("Failed to set text field.");
}
// Leave bodyReader open so that the db can read from it. It *should*
// be garbage collected after it's done without needing to call close.}
int parameterIndex, String value) throws SQLException
{
Reader bodyReader = null;
try {
bodyReader = new StringReader(value);
pstmt.setCharacterStream(parameterIndex, bodyReader, value.length());
}
catch (Exception e) {
e.printStackTrace();
throw new SQLException("Failed to set text field.");
}
// Leave bodyReader open so that the db can read from it. It *should*
// be garbage collected after it's done without needing to call close.}
getAsciiStream materializes the CLOB value as a byte stream containing Ascii bytes Clob notes = rs.getClob("NOTES");
java.io.InputStream in = notes.getAsciiStream();
byte b = in.read();
// in contains the characters in the CLOB value designated by
// notes as Ascii bytes; b contains the first character as an Ascii
// byte
getCharacterStream materializes the CLOB value as a stream of Unicode characters java.io.Reader reader = notes.getCharacterStream();
int c = Reader.read();
// c contains the first character in the CLOB that notes designates
getSubString materializes all or part of the CLOB value as a String object String substring = notes.getSubString(10, 5);
// substring contains five characters, starting with the tenth
// character of the CLOB value that notes designates
long len = notes.length();
String substring = notes.getSubString(1, len);
// substring contains all of the characters in the CLOB object that
char[] chr = new char[Integer.parseInt(String.valueOf(clob.length))];
Read read = clob.getCharacterStream();
read.read(chr);
String str = new String(chr);