Oracle rs.getClob("")转String
oracle数据中定义为clob类型的字段,如果用rs.getString()方法获取,值一直为nul,无法取出
用rs.getClob()取出来为Clob型
需把Clob型转为String类型
Java 代码
rs = pstmt.executeQuery();
while(rs.next()){
Reader reader = rs.getClob("afterStepScript")
.getCharacterStream();
BufferedReader r = new BufferedReader(reader);
StringBuffer sb = new StringBuffer();
String line;
try {
while ((line = r.readLine()) != null) {
sb.append(line);
//sb.append("\r\n");
}
} catch (IOException e) {
e.printStackTrace();
}
String afterStepScript=sb.toString();
或者
Clob clob=rs.getClob("insideScript");
String insideScript="";
if(clob!=null){
insideScript=clob.getSubString((long)1, (int)clob.length());
}
后一种方式效率更高一些
by archie
posted on 2012-03-08 09:15 archie2010 阅读(1847) 评论(0) 编辑 收藏 举报