| Oracle FAQ | Your Portal to the Oracle Knowledge Grid | |
|  |  | |||
Home -> Community -> Usenet -> c.d.o.misc -> question about storing blobs from bfiles in java
Hello,
I have a problem storing a blob with java. My way to store the blob looks like this:
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
// --- snip ---- Received on Tue Sep 07 1999 - 03:02:45 CDT
|  |  |