100分求解如果在DB2中存取CLOB二进制大对象字符串

pleonheart 2003-09-09 12:02:35
RT,谢谢
...全文
99 5 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
conning333 2003-09-09
  • 打赏
  • 举报
回复
包可用:

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.}
pleonheart 2003-09-09
  • 打赏
  • 举报
回复
一个恶心的男人告诉我了,谢谢楼上的两位

Clob clob = rs.getClob("content");
char[] chr = new char[Integer.parseInt(String.valueOf(clob.length))];
Read read = clob.getCharacterStream();
read.read(chr);
String str = new String(chr);
netcobol 2003-09-09
  • 打赏
  • 举报
回复
使用biye[]好像可以,用setClob,读代码如下
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
pleonheart 2003-09-09
  • 打赏
  • 举报
回复
到底是用setCharacterStream还是setClob啊?
pleonheart 2003-09-09
  • 打赏
  • 举报
回复
那读呢老大?

67,550

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧