我在Oracle 9的数据库blob列中存储了一些文件。
我想将那些文件存储在文件系统中。
这应该很容易,但是我找不到正确的选择。
如何在Java中执行此操作?
PreparedStatement ptmst = ...
ResutlSet rs = pstmt.executeQuery();
rs.getBlob();
// mistery
FileOutputStream out = new FileOutputStream();
out.write(); // etc et c
我知道应该是这样的…我不知道被评论为有 雾
谢谢
编辑
我终于从大卫的问题中得到了这一点。
这是我的懒惰实现:
PreparedStatement pstmt = connection.prepareStatement("select BINARY from MYTABLE");
ResultSet rs = pstmt.executeQuery();
while( rs.next() ) {
Blob blob = rs.getBlob("BINARY");
System.out.println("Read "+ blob.length() + " bytes ");
byte [] array = blob.getBytes( 1, ( int ) blob.length() );
File file = File.createTempFile("something-", ".binary", new File("."));
FileOutputStream out = new FileOutputStream( file );
out.write( array );
out.close();
}