This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Websphere and the fly likes Inserting Image into Oracle. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Products » Websphere
Bookmark "Inserting Image into Oracle." Watch "Inserting Image into Oracle." New topic

Inserting Image into Oracle.

Joseph Hatton

Joined: Dec 12, 2002
Posts: 20
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
BLOB blob = ((OracleResultSet)rs).getBLOB(1);
String imageData = getTransactionData(transIndex).getString(IChgbkModel.IMAGE);
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 = != -1){
outstream.write(buffer, 0, length);
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:
Any help would be appreciated.
I agree. Here's the link:
subject: Inserting Image into Oracle.
Similar Threads
Reading From a Binary Large Object(BLOB)
ClassCastException when casting my resultset to OracleResultSet
uploading image into oracle database through servlet
java.sql.sqlexception data size bigger than max size for this type
Facing problem in loading embadded image from xls sheet into oracle database