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

Home -> Community -> Usenet -> c.d.o.server -> Re: java stored procedure code example

Re: java stored procedure code example

From: Rauf Sarwar <rs_arwar_at_hotmail.com>
Date: 4 Oct 2002 15:04:00 -0700
Message-ID: <92eeeff0.0210041404.610d16c7@posting.google.com>


"Jeremy Ovenden" <newsposter_at_hazelweb.co.uk> wrote in message news:<ank7g3$eubun$1_at_ID-140241.news.dfncis.de>...
> Looking for help with the following. I have a table with a BLOB
> column containing binary data (e.g. MS Word docs, jpeg images
> etc.)
>
> I want to write these files out to a BFILE on the o/s.
>
> I believe the only method for doing this is to either write an
> external proc or to write a jsp to do it. Not knowing java is a
> handicap! So am looking to see if anyone has done something
> similar and could at least share an outline?
>
> BTW this an Oracle 8.1.7+ database.
>
> TIA

  1. For starters, you can read up on Oracle's DBMS_LOB package.
  2. To use Java for this... you can look up java.sql and java.io api's in JavaDocs. I haven't tested this but here is sort of a pseudo code that I can think of.
    • Open a JDBC connection to Oracle database Connection con = ...... Statement stmt = con.createStatement ..... Resultset rs = stmt.executeQuery(Select .....)
    • Create an instance of Blob Blob blob = rs.getBlob(column index (int) or name (String)). if blob = null {return;}
    • Create an instance of BufferedInputStream BufferedInputStream bis = new BufferedInputStream(blob.getInputStream())
    • Specify a byte[] buffer size e.g. 4096 byte[] buf = new byte[4096];
    • Create an instance of FileOutputStream FileOutputStream fos = new FileOutputStream(file name)
    • Read bytes from BufferedInputStream and write to FileOutputStream while (bis.read into buf does not return -1) fos.write(write to specified file from buf)
    • Close all Streams bis.close() fos.close()

/Rauf Sarwar Received on Fri Oct 04 2002 - 17:04:00 CDT

Original text of this message

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