Home >Database >Mysql Tutorial >Java获取Oracle中CLOB字段转换成String

Java获取Oracle中CLOB字段转换成String

WBOY
WBOYOriginal
2016-06-07 17:10:491734browse

Java获取Oracle中CLOB字段转换成String : try {PreparedStatement stmt = session.connection().prepareStatement(sql); Result

Linux公社

首页 → 数据库技术

背景:

阅读新闻

Java获取Oracle中CLOB字段转换成String

[日期:2012-02-05] 来源:Linux社区  作者:Linux [字体:]

Java获取Oracle中CLOB字段转换成String :

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;
}

linux

  • 0
  • Oracle date timestamp 毫秒 - 时间函数总结

    FreeBSD 7.2下安装MySQL 4.0

    相关资讯       Oracle基础教程 

    图片资讯      

    本文评论   查看全部评论 (0)

    评论声明

    最新资讯

    本周热门

    Linux公社简介 - 广告服务 - 网站地图 - 帮助信息 - 联系我们
    本站(LinuxIDC)所刊载文章不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。


    Copyright © 2006-2011 Linux公社 All rights reserved 浙ICP备06018118号

    Statement:
    The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn