Retrieving image from Oracle database
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.
public Blob getBlob()throws SQLException
Signature of getBytes() method of Blob interface
public byte[] getBytes(long pos, int length)throws SQLException
We are assuming that image is stored in the imgtable.
CREATE TABLE "IMGTABLE"
( "NAME" VARCHAR2(4000),
"PHOTO" BLOB
)
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.
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.
public Blob getBlob()throws SQLException
Signature of getBytes() method of Blob interface
public byte[] getBytes(long pos, int length)throws SQLException
We are assuming that image is stored in the imgtable.
CREATE TABLE "IMGTABLE"
( "NAME" VARCHAR2(4000),
"PHOTO" BLOB
)
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.