Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
![]() |
![]() |
Home -> Community -> Mailing Lists -> Oracle-L -> Java to write a blob to disk, does any one have the java to read a blob from disk
>From Mark A. Williams from Indianapolis, IN USA
Here is the script in java to save a blob to disk (works perfectly)
Adjust for your environment and line wrapping may need to be undone...
connect / as sysdba;
grant javauserpriv to scott;
begin
dbms_java.grant_permission('SCOTT',
'java.io.FilePermission','c:\temp\blob.txt', 'write');
end;
/
connect scott/tiger;
create or replace java source named "exportBLOB" as
import java.lang.*; import java.io.*; import java.sql.*;
// get an input stream from the blob InputStream l_in = p_blob.getBinaryStream();
// get buffer size from blob and use this to create buffer for stream
int l_size = p_blob.getBufferSize();
byte[] l_buffer = new byte[l_size];
int l_length = -1;
// write the blob data to the output stream while ((l_length = l_in.read(l_buffer)) != -1) {
l_out.write(l_buffer, 0, l_length); l_out.flush();
// close the streams
l_in.close();
l_out.close();
}
};
/
-- Archives are at http://www.freelists.org/archives/oracle-l/ FAQ is at http://www.freelists.org/help/fom-serve/cache/1.html -----------------------------------------------------------------Received on Thu Feb 26 2004 - 09:46:27 CST
![]() |
![]() |