import java.sql.*;
import java.io.*;
public class JdbcPhotoRetrive
{
public static void main(String args[]) throws Exception
{
//load the register driver
Class.forName("oracle.jdbc.driver.OracleDriver");
//establish the connection
Connection con=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe","system","myoracle");
//create the statement object
PreparedStatement ps=con.prepareStatement("select * from imgtable");
ResultSet rs=ps.executeQuery();
if(rs.next())
{
Blob b=rs.getBlob(2);
byte brr[]=b.getBytes(1,(int)b.length());
FileOutputStream fout=new FileOutputStream("d:\\p.jpg");
fout.write(brr);
fout.close();
System.out.println("Success");
}
}
}