Sample to recover picture from Oracle database

By the offer of PreparedStatement we some assistance with canning recover and store the picture in the database. 

The getBlob() strategy for PreparedStatement is utilized to get Binary data, it gives back the occurrence of Blob. In the wake of calling the getBytes() technique on the blob object, we can get the variety of parallel data that can be built into the picture record. 

Mark of getBlob() strategy for PreparedStatement 

open Blob getBlob()throws SQLException 

Mark of getBytes() strategy for Blob interface 

open byte[] getBytes(long pos, int length)throws SQLException 

We are accepting that picture is put away in the imgtable. 


( "NAME" VARCHAR2(4000), 

"Photograph" BLOB 



Presently we should compose the code to recover the picture from the database and compose it into the catalog so it can be shown. 

In AWT, it can be shown by the Toolkit class. In servlet, jsp, or html it can be shown by the img tag. 

import java.sql.*; 


open class RetrieveImage { 

open static void main(String[] args) { 



Association con=DriverManager.getConnection( 


PreparedStatement ps=con.prepareStatement("select * from imgtable"); 

ResultSet rs=ps.executeQuery(); 

if({//now on first line 

Blob b=rs.getBlob(2);//2 implies second section information 

byte barr[]=b.getBytes(1,(int)b.length());//1 implies first picture 

FileOutputStream fout=new FileOutputStream("d:\\sonoo.jpg"); 



}//end of if 



}catch (Exception e) {e.printStackTrace(); }