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

zhu_liping 2002-03-05 04:49:25
各位,帮帮我好吗?
...全文
82 9 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
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?

81,122

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧