执行以下程序会出现错误,
Exception in thread "main" java.lang.AbstractMethodError: oracle.jdbc.driver.OraclePreparedStatement.setBlob(ILjava/io/InputStream;)V
at ImageStore.main(ImageStore.java:28)
我使用的是 ojdbc14.jar,我的 Oracle 版本是 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();
}
}
请帮忙
最佳答案
我还必须在数据库中插入图像,其工作方式如下
将图像转换为Byte数组
使用 setBinaryStream,其中数据是字节数组
preparedStatement.setBinaryStream(1,new ByteArrayInputStream(data),data.length);
编辑:这种技术的缺点是数组的整数限制大小
关于java - 在数据库中插入图像时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9436717/