Tuesday 31 January 2017

Example to retrieve image from Oracle database:

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.


JavaCoders

CODING AND PROGRAMMING:

This blog contains all the information regarding java coding and the programs, where all the coders can share and learn. This blog contains all the codes regarding:

JSP
Servlets
Hibernate
Core Java
Advanced Java
Github
Programs regarding Strings..

Please comments ,share the posts and follow for more posts..

Oracle / PLSQL: FOR LOOP

set serveroutput on; declare a1 varchar2(100); begin select count(*) into a1 from employees; for i in 1..a1 loop dbms_output.put_line...