利用oracle long类型字段问题

今天上午突然解决了这个问题,真是高兴,主要参考文章:

http://dev2dev.bea.com.cn/bbs/thread.jspa?forumID=123&threadID=17121&messageID=97829

 我在编写应用时,需要大量的插入大文本,但是oracle 的clob操作起来比较繁琐,应此我没有选择使用clob,而是使用了oracle以前版本中的long类型[但是long类型有一些限制,在一个表中只能有一个long字段]。
开始的时候我直接使用insert into table1 values(a,b[long])的方式插入数据库,但是oracle有些限制一条语句不能超过4000个字符,并报ORA-01704的错误。
经过查找oracle 的文档找到了解决的方法,就是对于long的字段使用setCharacterStream()方法将String插入数据库。

代码:
sql="insert into msg_info values (?,?,?,?[long类型字段],'C',sysdate,sysdate+"+msgterm+",?)";
pstat1 = conn.prepareStatement(sql);
pstat1.setLong(1, msg_id);
      pstat1.setInt(2, msg_gp_id);
      pstat1.setString(3, msg_title);
      pstat1.setCharacterStream(4,new StringReader(msg_info.toString()),msg_info.length());
conn.commit();

      pstat1.setLong(5, this.upid);

setCharacterStream

void setCharacterStream(int parameterIndex,
                        Reader reader,
                        int length)
                        throws SQLException
Sets the designated parameter to the given Reader object, which is the given number of characters long. When a very large UNICODE value is input to a LONGVARCHAR parameter, it may be more practical to send it via a java.io.Reader object. The data will be read from the stream as needed until end-of-file is reached. The JDBC driver will do any necessary conversion from UNICODE to the database char format.

Note: This stream object can either be a standard Java stream object or your own subclass that implements the standard interface.

本来这个问题早就该解决,经验再次重复:API 非常重要,J2SE, J2EE , Oracle 的API,比任何参考书都有用!!!

还有就是要广泛利用资源.

再次感谢作者的那篇重要的文章!

现在还残留的问题是,我在oracle里面插入了blob(图片),也能正常显示,可是,用select 语句却看不见?!

现在不知道要找那个API了.....

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值