Inser a BLOB object in Java


import java.sql.*;
import java.util.*;
import java.io.*;


public class InsertBlobExample {
public static void main(String s[]) throws Exception {


Driver d= (Driver) ( Class.forName( 
"oracle.jdbc.driver.OracleDriver").newInstance());


Properties p=new Properties ();
p.put("user","scott");
p.put("password","tiger");


Connection con=d.connect(
"jdbc:oracle:thin:@mysys:1521:Javastuff",p);


PreparedStatement ps= con.prepareStatement(
"insert into personaldetails(empno,photo) values(?,?)");


ps.setInt(1,Integer.parseInt(s[0]));
File f=new File("MyImage.jpg");
FileInputStream fis= new FileInputStream(f);
ps.setBinaryStream(2,fis, (int)f.length());
int i=ps.executeUpdate();
System.out.println("Record inserted successfully , count : "+i);
con.close();
}//main
}//class



Enter your email address to get our daily JOBS & INTERVIEW FAQ's Straight to your Inbox.

Make sure to activate your subscription by clicking on the activation link sent to your email