• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

Inserting Image into Oracle.

 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Since the image is coming in as a byte array, the "insert" statement wouldn't make sense since I am building the SQL String in Java and would make a messy conversion and storing the "image" as blob in the Oracle database.
I am inserting an image in a round-about way.
Here is the code:
//Pass the ResultSet(rs) to this method.
//The sql is "select image from image_table where chgbk_id=12345
try{
BLOB blob = ((OracleResultSet)rs).getBLOB(1);
String imageData = getTransactionData(transIndex).getString(IChgbkModel.IMAGE);
if(imageData==null){
throw new Exception("Image data is null.");
}
ImageModel image = new ImageModel(imageData);
InputStream instream = new ByteArrayInputStream(image.getImageData());
OutputStream outstream = blob.getBinaryOutputStream();
int size = blob.getBufferSize();
byte[] buffer = new byte[size];
int length = -1;

/**
* 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();
}
catch(Exception exc){
throw new DatasourceException("Error when trying to update Image BLOB data.", exc);
}

When this code is applied to Connection Pooling in WebSphere 4.0.3 server it doesn't like the "OracleResultSet" object I am using. I get this error:
java.lang.ClassCastException: com.ibm.ejs.cm.proxy.ResultSetProxy
Any help would be appreciated.
 
A wop bop a lu bop a womp bam boom! Tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic