Illustration to store picture in Oracle database

You can store pictures in the database in java by the help of PreparedStatement interface. 

The setBinaryStream() system for PreparedStatement is utilized to set Binary data into the parameterIndex. 

Mark of setBinaryStream system 

The sentence structure of setBinaryStream() strategy is given underneath: 

1) open void setBinaryStream(int paramIndex,InputStream stream) 

tosses SQLException 

2) open void setBinaryStream(int paramIndex,InputStream stream,long length) 

tosses SQLException 

For putting away picture into the database, BLOB (Binary Large Object) datatype is utilized as a part of the table. For instance: 


( "NAME" VARCHAR2(4000), 

"Photograph" BLOB 



How about we compose the jdbc code to store the picture in the database. Here we are utilizing d:\\d.jpg for the area of picture. You can transform it as indicated by the picture area. 

import java.sql.*; 


open class InsertImage { 

open static void main(String[] args) { 



Association con=DriverManager.getConnection( 


PreparedStatement ps=con.prepareStatement("insert into imgtable values(?,?)"); 


FileInputStream fin=new FileInputStream("d:\\g.jpg"); 


int i=ps.executeUpdate(); 

System.out.println(i+" records influenced"); 


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



On the off chance that you see the table, record is put away in the database however picture won't be appeared. To do as such, you have to recover the picture from the database which we are covering in the following page.