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

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

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 11:38:15 -0400
Message-ID: <023f01c3fc7e$8d00e1f0$2501a8c0@dazasoftware.com>


>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();
    }
};
/


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 - 09:46:27 CST

Original text of this message

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