今天上午突然解决了这个问题,真是高兴,主要参考文章:
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
Readerobject, which is the given number of characters long. When a very large UNICODE value is input to aLONGVARCHARparameter, it may be more practical to send it via ajava.io.Readerobject. 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了.....
作者在编写应用时需大量插入大文本,未选择操作繁琐的Oracle clob类型,而是用long类型。直接插入时因Oracle限制报错,后通过查找文档,使用setCharacterStream()方法将String插入数据库,并给出了相应代码。

869

被折叠的 条评论
为什么被折叠?



