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 -> BLOB Manipulation

BLOB Manipulation

From: Aviran Levy <avlevy2k_at_hotmail.com>
Date: Thu, 25 Oct 2001 15:58:01 -0400
Message-ID: <M9_B7.308$0N4.36795@news.shore.net>


Thanks for the help,
First I would like to ask if the book "Oracle8i JDBC Developer's Guide and Reference" is available online.

As for the solution you described in your message, When I try to run it I get an exception thrown from the oracle server saying that the "row containing the lob object is not locked". I know that if I run a stored procedure to manipulate a BLOB object I can lock the row by adding the 'for update' to the select query and the 'commit' after making the modification. That's obviously not the case here. any ideas how to lock a row in java code?

Furthermore, do you happen to know a place when I can get the documentation for the oracle BLOB object since I also need to access the data in the BLOB. in the example you gave in your message I would like also to do the opposite - how is it possible to get data from the BLOB object and store it in a new file ?

Thanks a lot
-- Avi

"Sergey M" <msu_at_pronto.msk.ru> wrote in message news:9r8lnt$116k$1_at_serv2.vsi.ru...
> "Aviran Levy" <avlevy2k_at_hotmail.com> сообщил/сообщила в новостях
следующее:
> news:ZfAB7.133$0N4.17635_at_news.shore.net...
> > Hi,
> > From a java application I'm trying to do:
> > ...
> > Blob b = rs.getBlob("ZIP_FILE");
> > b.setBytes(1,byteArray);
> > ...
> > but apparently I get a runtime exception since my oracle jdbc driver
> doesn't
> > have implementation for the setBytes method. I probably need a newer
> oracle
> > jdbc driver. Is anyone know where can I find one?
> > Is anyone having that problem too?
> > My goal is to store a zip file on the Oracle server and manipulate it
from
> > the java application (avoiding calls for store procedures). If anyone
> knows
> > a better way to do that then please... I'll appreciate any help about
it.
> > Note: to use setBytes you have to use JDK1.4
> > Thanks,
> > -- Avi
>
> 1. Begin by using SQL statements to create the BLOB entry in the table.
> Use the empty_blob syntax to create the BLOB locator.
>
> stmt.execute ("INSERT INTO my_blob_table VALUES ('row1',
> empty_blob())");
>
> 2. Get the BLOB locator from the table.
>
> BLOB blob;
> cmd = "SELECT * FROM my_blob_table WHERE X='row1'";
> ResultSet rest = stmt.executeQuery(cmd);
> BLOB blob = ((OracleResultSet)rset).getBLOB(2);
>
> 3. Declare a file handler for the john.gif file, then print the length of
> the file. This value will be used later
> to ensure that the entire file is read into the BLOB. Next, create a
> FileInputStream object to read the
> contents of the GIF file, and an OutputStream object to retrieve the
> BLOB as a stream.
>
> File binaryFile = new File("YOUR_ZIP_FILE");
> System.out.println("john.gif length = " + binaryFile.length());
> FileInputStream instream = new FileInputStream(binaryFile);
> OutputStream outstream = blob.getBinaryOutputStream();
>
>
> 4. Call getBufferSize() to retrieve the ideal buffer size (according to
> calculations by the JDBC driver) to use in
> writing to the BLOB, then create the buffer byte array.
>
> int size = blob.getBufferSize();
> byte[] buffer = new byte[size];
> int length = -1;
>
> 5. Use the read() method to read the GIF file to the byte array buffer,
then
> use the write() method to write it to
> the BLOB. When you finish, close the input and output streams.
>
> while ((length = instream.read(buffer)) != -1)
> outstream.write(buffer, 0, length);
> instream.close();
> outstream.close();
>
> This fragment is from "Oracle8i JDBC Developer's Guide and Reference"
> charpter 7 "Working with LOBs and BFILEs"
>
> Sergey M.
>
> P.S. Knowledge is of two kinds. We know a subject ourselves, or we know
> where we can find information upon it. --Samuel Johnson
>
>
Received on Thu Oct 25 2001 - 14:58:01 CDT

Original text of this message

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