oracle将clob显示为html类型,将网页文本(HTML)封存到ORACLE数据库CLOB字

网上常见的例子总是将文本文件上传至数据库的方法。今天在做文档管理相关系统时,需要将网页上的文本输入框(textarea或input)中的内容,上传到ORACLE数据库的CLOB字段中去。在网上找了好长时间,总算有所收获,现将方法总结如下,其中部分代码为其它网友的源码:

一、上传

private void updateContent(Connection conn, Information info) throws

Exception {

PreparedStatement pstmt = conn.prepareStatement(

"SELECT CONTENT FROM INFO_CONTENT WHERE ID=? FOR UPDATE");

pstmt.setInt(1, info.getId());

ResultSet rs = pstmt.executeQuery();

/* 取出此CLOB对象 */

if (rs.next()) {

//Weblogic这样写

OracleThinClob clob = (OracleThinClob) rs.getClob(1);

//其它服务器这样写

//oracle.sql.CLOB clob = (oracle.sql.CLOB) rs.getClob(1);

/* 向CLOB对象中写入数据 */

/*

//保存文件

//BufferedWriter out = new BufferedWriter(clob.getCharacterOutputStream());

//BufferedReader in = new BufferedReader(new FileReader(filename));

*/

//保存字符串

Writer out = clob.getCharacterOutputStream();

out.write(info.getContent());

out.flush();

out.close();

rs.close();

pstmt.close();

}

}

二、在jsp中显示

本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/whirlsun/archive/2005/07/16/427013.aspx

public Information getInformation(int id) throws Exception {

Information base = new Information();

Connection conn = null;

try {

conn = DBConnect.GainDBConnect();

PreparedStatement ps = conn.prepareStatement(

"SELECT * FROM INFO_CONTENT WHERE ID=?");

ps.setInt(1, id);

ResultSet rs = ps.executeQuery();

while (rs.next()) {

java.sql.Clob clob = (java.sql.Clob) rs.getClob("CONTENT");

/* 以字符形式输出 */

Reader out = new BufferedReader(clob.getCharacterStream());

BufferedReader bfClob = new BufferedReader(out);

String strClob = bfClob.readLine();

StringBuffer sbResult = new StringBuffer();

while (strClob != null) {

sbResult.append(strClob);

strClob = bfClob.readLine();

}

base.setContent(sbResult.toString());

out.close();

}

rs.close();

ps.close();

}

catch (Exception ex) {

System.out.println(ex);

throw ex;

}

finally {

conn.close();

}

return base;

}

本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/whirlsun/archive/2005/07/16/427013.aspx

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值