19.Retrive blob data


import java.sql.*;
import java.io.*;
public class retrive {
public static void main(String[] args) {
try{
Class.forName(“com.mysql.jdbc.Driver”);
Connection con=DriverManager.getConnection(“jdbc:mysql://localhost:3306/demo”,”root”,””);

PreparedStatement ps=con.prepareStatement(“select * from student_profile”);
ResultSet rs=ps.executeQuery();
if(rs.next()){//now on 1st row

Blob b=rs.getBlob(2);//2 means 2nd column data
byte barr[]=b.getBytes(1,(int)b.length());//1 means first image

FileOutputStream fout=new FileOutputStream(“E:\\pooja11.jpg”);
fout.write(barr);

fout.close();
}//end of if
System.out.println(“ok”);

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