高分求救:谁用过JSP处理ORACLE数据库中的LONG RAW类型字段

zhu_liping 2002-03-05 04:49:25
各位,帮帮我好吗?
...全文
19 点赞 收藏 9
写回复
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
zhangyonggang 2002-03-08
写入:
out = response.getWriter();
Connection conn = DriverManager.getConnection("", "", "");
//INSERT A FILE INTO THE DATABASE!
File file = new File("D:\\d.bmp");
FileInputStream fis = new FileInputStream(file);
String strsql ="INSERT INTO tp(tp,dm) VALUES (?,'01')";
PreparedStatement ps = conn.prepareStatement(strsql);
ps.setBinaryStream(1, fis, (int)(file.length()));
ps.executeUpdate();
out.println("INSERT FILE OK:::::");
ps.close();
fis.close();
读出:
PreparedStatement pres = conn.prepareStatement("SELECT tp FROM tp WHERE dm='01'");
ResultSet res = pres.executeQuery();
if (res != null)
{
while(res.next())
{
InputStream is = res.getBinaryStream(1);
// use the stream in some way here
OutputStream outstr = new BufferedOutputStream( new FileOutputStream("d:\\new.bmp"));
// Read the URL and write it to a file
byte bufferb[] = new byte[64];
// Buffer to store lines
int nread;
while(0<=(nread = is.read(bufferb)))
outstr.write(bufferb, 0, nread);
is.close();
outstr.close();
}
res.close();
}
pres.close();
回复
zhu_liping 2002-03-07
我用的是ORACLE7呀,那怎么办呢?
回复
lun2001 2002-03-07
不过要用oracle 8i的jdbc驱动程序才可以正确执行
回复
lun2001 2002-03-07
String sSql=""update test set content = ? where id = 1";
String=content"my god";//你的内容
PreparedStatement stmt = conn.prepareStatement(sSql);
byte[] pic = content.getBytes();
InputStreamReader bais = new InputStreamReader(new ByteArrayInputStream(pic));
stmt.setCharacterStream(1, bais, pic.length);
stmt.execute();

写2k以上文本不用LONG RAW
用long就可以了
以上程序是针对LONG的
写long raw大概应该用setBinaryStream
试一试...
回复
lun2001 2002-03-07
只要有oracle8i的jdbc就行
它兼容oracle7
回复
yanchang 2002-03-06
yong 用clob不好吗?
回复
xmhjs 2002-03-06
ORACLE7还是oracle8i以上,有区别的
回复
zhu_liping 2002-03-06
也就是说,ORACLE想存放大于2K的文本,怎么做呢?
回复
yanchang 2002-03-05
Why?
回复
发动态
发帖子
Web 开发
创建于2007-09-28

7.9w+

社区成员

Java Web 开发
申请成为版主
社区公告
暂无公告