Reputation: 2187
Executing below programs is giving me error as,
Exception in thread "main" java.lang.AbstractMethodError: oracle.jdbc.driver.OraclePreparedStatement.setBlob(ILjava/io/InputStream;)V
at ImageStore.main(ImageStore.java:28)
I'm using ojdbc14.jar and my Oracle version is 9.0.1.1.1
public class ImageStore {
/**
* @param args
* @throws Exception
*/
public static void main(String[] args) throws Exception {
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection con = DriverManager
.getConnection("jdbc:oracle:thin:@localhost:1521:orcl",
"usrname", "password");
String sql="update items set image=? where id=1";
//String sql="select * from price";
PreparedStatement ps=con.prepareStatement(sql);
File f=new File("E:/Images/s.jpg");
InputStream fos= new FileInputStream(f);
ps.setBlob(1, fos);
ps.execute();
/*while(rs.next())
System.out.println(rs.getInt(1));
*/
ps.close();
con.close();
}
}
Please help
Upvotes: 0
Views: 909
Reputation: 11110
AbstractMethodError
suggests that you are not working with the proper driver. If you are using java5 or above, try downloading the appropriate ojdbc driver (ojdbc14.jar is for java1.4)
http://www.oracle.com/technetwork/database/enterprise-edition/jdbc-111060-084321.html
Upvotes: 0
Reputation: 3091
I had to insert image also in a database and the way it worked was the following
Convert the image to an array of Byte
Use setBinaryStream where data is an array of Byte
preparedStatement.setBinaryStream(1,new ByteArrayInputStream(data),data.length);
EDIT: The downfall of this technique is that the integer limitation size for an array
Upvotes: 1