Code:
package com;
import java.io.*;
import java.sql.*;
public class Sample {
public static void main(String a[]){
Connection con = null;
PreparedStatement ps = null;
InputStream is = null;
try {
Class.forName("oracle.jdbc.driver.OracleDriver");
con = DriverManager.getConnection("jdbc:oracle:thin:@172.26.132.40:1521:orclilp","aja60core","aja60core");
ps = con.prepareCall("insert into SAMPLE values (?,?,?)");
ps.setString(1, "Himanshu");
ps.setString(2, "Gupta");
is = new FileInputStream(new File("ajax-logo1.jpg"));
ps.setBinaryStream(3, is);
int count = ps.executeUpdate();
System.out.println("Count: "+count);
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally{
try{
if(is != null) is.close();
if(ps != null) ps.close();
if(con != null) con.close();
} catch(Exception ex){}
}
}
}
And I'm getting the following error:
java.io.FileNotFoundException: ajax-logo1.jpg (The system cannot find the file specified)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(FileInputStream.java:138)
at com.Sample.main(Sample.java:19)