ITPub博客

首页 > 数据库 > Oracle > java获取oracle中CLOB字段,转换成String

java获取oracle中CLOB字段,转换成String

原创 Oracle 作者:haijie1984 时间:2009-02-03 16:06:02 0 删除 编辑

try {
PreparedStatement stmt = session.connection().prepareStatement(sql);
ResultSet rs = stmt.executeQuery();
while (rs.next())
{
Clob clob = (Clob)rs.getObject(1);
result = ClobToString(clob);
}

} catch (HibernateException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
session.close();
}

//oracle.sql.Clob类型转换成String类型

public String ClobToString(Clob clob) throws SQLException, IOException {

String reString = "";
Reader is = clob.getCharacterStream();// 得到流
BufferedReader br = new BufferedReader(is);
String s = br.readLine();
StringBuffer sb = new StringBuffer();
while (s != null) {// 执行循环将字符串全部取出付值给StringBuffer由StringBuffer转成STRING
sb.append(s);
s = br.readLine();
}
reString = sb.toString();
return reString;
}

[@more@]

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/7282477/viewspace-1016630/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2009-06-23

  • 博文量
    37
  • 访问量
    415685