如果你一定要用BLOB存储,你就必须用Oracle自己的方法:
create table tb_file(name varchar(20),detail BLOB);
con.setAutoCommit(false);
stmt.executeUpdate("insert into tb_file values
(´aaa.gif´,empty_blob())");
|
下面必须SELECT得到BLOB的对象再向里写:
rs = stmt.executeQuery
("select detail from tb_file
where name=´aaa.gif´
for upfdate" );
if(rs.next())
{
Blob blob = rs.getBlob(1);
BinaryOutputStream out =
((oracle.sql.BLOB)blob).getBinaryOutputStream();
byte[] b = new byte
[((oracle.sql.BLOB)blob).getBufferSize];
InputStream fin = new FileInputStream(file);
int len = 0;
while( (len = fin.read(b)) != -1)
out.write(b,0,len);
fin.close();
out.close();
con.commit();
}
|
同样读取数据你并不能象LONG ROW那样
InputStream in = rs.getBinaryInputStream("detail");
|
而要:
Blob blob = rs.getBlob("detail");
in = blob.getBinaryStream();
|
问题三:可滚动结果集
Oracle明确说明不支持结果集滚动,那么我们用JDBC2得到一个可滚动的结果集就是同JDBC自己支持的,就是说结果集要在内在中高度缓存,很多很多的开发者都错误地认为是数据库支持的。只是他们没有真正查询大量行,如果真的查询大量行的话肯定是死定了!对于超大量行的数据,情愿返回到它的笨方法也不要使用可滚动结果集。 (责任编辑:卢兆林)
<<上一页
1
2
|