我有一些文件存储在 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();
}