Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
![]() |
![]() |
Home -> Community -> Mailing Lists -> Oracle-L -> Re: Java to write a blob to disk, does any one have the java to read a blob from disk
Your Java example is used to get data from PL/SQL to disk.
If you MUST use java to go the other way, I cannot help.
If you want to get from a disk file to a PL/SQL blob there is
no need for java - use BFILE.
Garry Gillies
Database Administrator
Business Systems
Weir Pumps Ltd
149 Newlands Road, Cathcart, Glasgow, G44 4EX
T: +44 0141 308 3982 F: +44 0141 633 1147 E: g.gillies_at_weirpumps.com "Juan Cachito Reyes Pacheco" To: <oracle-l_at_freelists.org> <jreyes_at_dazasoftwa cc: re.com> Subject: Java to write a blob to disk, does any one have Sent by: the java to read a blob from disk oracle-l-bounce_at_fr eelists.org 26/02/04 15:38 Please respond to oracle-l
>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 ----------------------------------------------------------------- CONFIDENTIAL: The information contained in this email (including any attachments) is confidential, subject to copyright and for the use of the intended recipient only. If you are not the intended recipient please delete this message after notifying the sender. Unauthorised retention, alteration or distribution of this email is forbidden and may be actionable. Attachments are opened at your own risk and you are advised to scan incoming email for viruses before opening any attached files. We give no guarantee that any communication is virus-free and accept no responsibility for virus contamination or other system loss or damage of any kind. ---------------------------------------------------------------- Please see the official ORACLE-L FAQ: http://www.orafaq.com ---------------------------------------------------------------- To unsubscribe send email to: oracle-l-request_at_freelists.org put 'unsubscribe' in the subject line. -- 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 - 10:16:50 CST
![]() |
![]() |