File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JDBC and Relational Databases and the fly likes Inserting image into the oracle database Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "Inserting image into the oracle database" Watch "Inserting image into the oracle database" New topic

Inserting image into the oracle database

Anirban dutta
Ranch Hand

Joined: Aug 08, 2002
Posts: 89
How can I insert an array of bytes obtained from an image into an Oracle BLOB type column using JDBC 2.0 type 4 driver?
Michael Morris
Ranch Hand

Joined: Jan 30, 2002
Posts: 3451
Moving this to the JDBC Forum

Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius - and a lot of courage - to move in the opposite direction. - Ernst F. Schumacher
Murali Nanchala
Ranch Hand

Joined: Mar 14, 2001
Posts: 74
If you have already extracted the byte array for the image, then try

You can also look at setBlob() method of the xxxxxxxxStatement object you use.

"It is almost always answered in the API" - Murali Nanchala
Anirban dutta
Ranch Hand

Joined: Aug 08, 2002
Posts: 89
I have tried out the method of the setBlob. But the problem is how to get the reference of the Blob interface. I couldn't find any code which returns the Blob's reference.
So I tried it in a different way:
I inserted a empty image into the database by empty_blob() function of SQL. Then I used the setBytes of the blob interface to set the image bytes in it. But it gave an runtime exception:
What could be the problem. Please help me in solving it.
Rene Larsen
Ranch Hand

Joined: Oct 12, 2001
Posts: 1179

Try this post:

Regards, Rene Larsen
Dropbox Invite
Sandeep Ghosh
Ranch Hand

Joined: Jan 23, 2002
Posts: 145
This is how I have done
I agree. Here's the link:
subject: Inserting image into the oracle database
It's not a secret anymore!