项目中用到了long raw 类型字段用于存放报表文件内容,一直相安无事。有一天需要修改设计,增加了一个跟报表组关联,问题来了,读取long raw字段总是提是SQLException“流已关闭”,经过一番较量,才算解决,在此和大家分享一下。
原来表结构:
create table reportview
(
id number(32) not null,
rptname varchar2(100) not null,
xmldata long raw not null,
primary key(id)
)
executeQuery("select * from reportview");
while(res.next())
{
res.getLong("id");
res.getString("rptname");
res.getBytes("xmldata");
}
没有问题,一切正常
后来多了个关联
create table reportview
(
id number(32) not null,
rptname varchar2(100) not null,
xmldata long raw not null,
groupid varchar2(100) not null
primary key(id)
)
当执行
executeQuery("select * from reportview");
while(res.next())
{
res.getLong("id");
res.getString("rptname");
res.getString("groupid");
res.getBytes("xmldata");
}
时就会抛出 java.sql.SQLException 流已关闭的错误
问题: 当然表中用到二进制字段时,要不按照select顺序和rs顺序相同来取,要不这个二进制字段要提前rs.getBytes("xmldata")
在继续说下插入的问题.
本来好好的,文件大到4k的时候有出现了,插入的异常.本来只想像普通对象那样定义
public class ReportView implements Serializable{
@Id
private Integer id;
@Lob
private byte[] xmldata;
}
em.persist(ReportView);
但是当文件超过4k,就不行了.想不出好的办法,只能用jdbc来实现