86
Example to retrieve image from Oracle database
By the help of PreparedStatement we can retrieve and store the image in the database.
The getBlob() method of PreparedStatement is used to get Binary information, it returns the instance of Blob. After calling the getBytes() method on the blob object, we can get the array of binary information that can be written into the image file.
Signature of getBlob() method of PreparedStatement
Signature of getBytes() method of Blob interface
We are assuming that image is stored in the imgtable.
Now let’s write the code to retrieve the image from the database and write it into the directory so that it can be displayed.
In AWT, it can be displayed by the Toolkit class. In servlet, jsp, or html it can be displayed by the img tag.
Now if you see the d drive, Tutoraspire.jpg image is created.
Next TopicStoring file in the database using java