import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;
public class StoreImage {
public static void main(String[] args) {
try(Connection con=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1522:xe","system","manager"))
{
File f=new File("D:/Lovely/Image/flower1.jpg");
FileInputStream fis=new FileInputStream(f);
PreparedStatement ps=con.prepareStatement("insert into emp2 values(?,?,?)");
ps.setInt(1, 111);
ps.setString(2, "Sameer");
ps.setBinaryStream(3,fis,f.length());
int rc=ps.executeUpdate();
System.out.println(rc+" row inserted");
}
catch(SQLException|IOException e)
{
e.printStackTrace();
}
}
}
import java.io.FileInputStream;
import java.io.IOException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;
public class StoreImage {
public static void main(String[] args) {
try(Connection con=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1522:xe","system","manager"))
{
File f=new File("D:/Lovely/Image/flower1.jpg");
FileInputStream fis=new FileInputStream(f);
PreparedStatement ps=con.prepareStatement("insert into emp2 values(?,?,?)");
ps.setInt(1, 111);
ps.setString(2, "Sameer");
ps.setBinaryStream(3,fis,f.length());
int rc=ps.executeUpdate();
System.out.println(rc+" row inserted");
}
catch(SQLException|IOException e)
{
e.printStackTrace();
}
}
}
0 Comment to "Java Program to insert an image in Oracle database"
Post a Comment