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

Home -> Community -> Usenet -> c.d.o.misc -> question about storing blobs from bfiles in java

question about storing blobs from bfiles in java

From: Christoph Dittberner <dittbern_at_zgdv.rostock.de>
Date: Tue, 7 Sep 1999 10:02:45 +0200
Message-ID: <37d4c6a5@news.uni-rostock.de>


Hello,

I have a problem storing a blob with java. My way to store the blob looks like this:

  1. I get the Inputstream from one BFILE
  2. I get the OutputStream for an empty blob At least I write the data from the InputStream(BFILE) to the OutputStream (BLOB). This works fine and without error messages or exceptions. But after this when I open the written BLOB for read I get a length of 0 returned

Thanks for any help.

I'm using Oracle Release 8.1.5.0.0, JDK 1.2.2, classes12.zip

the intial row was inserted like this:

    insert into multtable values (2, empty_blob() ); this is the code I used:

// ---- snip ----
 Connection connection;
 Statement stmt;
 ResultSet rSet = null;
 BFILE src_lob = null;
 oracle.sql.BLOB dest_lob = null;
 InputStream in = null;
 OutputStream out = null;
 byte buff[] = new byte[1000];

 rSet = stmt.executeQuery("SELECT BFILENAME('PICTUREDIR','lenncp.gif') from DUAL");  if (rSet.next())
{

  src_lob = ((OracleResultSet)rSet).getBFILE(1);   src_lob.openFile();
  in = src_lob.getBinaryStream();
 }
 rSet = stmt.executeQuery("SELECT photo from multtable where id=2 for UPDATE");  if (rSet.next())
{

  dest_lob = (oracle.sql.BLOB) ((OracleResultSet)rSet).getBLOB(1);   out = dest_lob.getBinaryOutputStream();

 } else { return; }
 int length = 0; int pos = 0;
 while ((in != null) && (out != null) && ((length = in.read(buff)) != -1))
{

  pos += length;
  out.write(buff,pos,length);
 }
 in.close(); out.flush(); out.close();
 src_lob.closeFile();
 connection.commit();
 rSet = stmt.executeQuery("SELECT photo from multtable where id=2");  if (rSet.next())
{

  dest_lob = ((OracleResultSet)rSet).getBLOB(1);   System.out.println(dest_lob.length());   // this statement should return the new length of the stored blob, but if the old blob was an empty blob it returns 0 for length,

  // if it wasn'nt empty it returns the old length
  // it looks like the new blob wasn't stored in the database
 // but I don't know why

 }
 connection.commit();

// --- snip ---- Received on Tue Sep 07 1999 - 03:02:45 CDT

Original text of this message

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