Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

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

Re: Java to write a blob to disk, does any one have the java to read a blob from disk

From: Juan Cachito Reyes Pacheco <jreyes_at_dazasoftware.com>
Date: Thu, 26 Feb 2004 14:42:02 -0400
Message-ID: <027401c3fc98$4451dcb0$2501a8c0@dazasoftware.com>


thanks

yes, but the problem is you have to create a directory and this is very annoying.

I think you talk about this
l_bfile := bfilename( 'MY_FILES', 'f.fmb' ); -- you have to create my_files directory object

dbms_lob.fileopen( l_bfile );

dbms_lob.loadfromfile( l_blob, l_bfile,

dbms_lob.getlength( l_bfile ) );

dbms_lob.fileclose( l_bfile );

If there is a way to avoid creating directories, and you know it this will be usefull to me.

> 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.*;
> import oracle.sql.*;
> public class exportBLOB
> {
> public static void do_export(BLOB p_blob, String p_file) throws
Exception
> {
> // create file output stream
> File l_file = new File(p_file);
> FileOutputStream l_out = new FileOutputStream(l_file);
>
> // 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();
> }
> };
> /
>
> -- the requisite plsql wrapper
> create or replace procedure exportBLOB (p_blob in blob, p_file in
varchar2)
> as
> language java name 'exportBLOB.do_export(oracle.sql.BLOB,
> java.lang.String)';
> /
>
> -- a small test of the above
> declare
> v_blob blob;
> v_raw raw(32);
> v_len number;
> begin
> -- create a raw to use in test
> v_raw := utl_raw.cast_to_raw('Oracle!');
> v_len := utl_raw.length(v_raw);
>
> -- create a temporary lob to test
> dbms_lob.createtemporary(v_blob, true);
> dbms_lob.write(v_blob, v_len, 1, v_raw);
>
> -- export it
> exportBLOB (v_blob, 'c:\temp\blob.txt');
> end;
> /
>
>
> ----------------------------------------------------------------
> 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
> -----------------------------------------------------------------
>
>
>
>
>
>
> 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
> -----------------------------------------------------------------



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 - 12:53:56 CST

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US