【发布时间】:2014-02-21 22:14:22
【问题描述】:
我写了以下代码:-
import java.sql.*;
import java.util.Properties;
import java.io.*;
public class Retrieving_Image {
public static void main(String[] args) throws Exception{
Properties p = new Properties();
p.put("user", "system");
p.put("password", "password");
DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
Connection con = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe",p);
PreparedStatement pstmt = con.prepareStatement("select * from picture",ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
ResultSet rs = pstmt.executeQuery();
rs.first();//retrieving only picture
Blob b = rs.getBlob(1);
byte arr[] = new byte[(int)b.length()];
arr = b.getBytes(1, (int)b.length());
FileOutputStream fos = new FileOutputStream("result.jpg");
fos.write(arr);
fos.close();
}
}
在上面的代码中,我试图检索位于结果集第一行的第一个索引中的图像,实际上结果集只有一行。但我收到以下错误:-
Exception in thread "main" java.lang.AbstractMethodError: oracle.jdbc.driver.ScrollableResultSet.getBlob(I)Ljava/sql/Blob;
at jdbc.Retrieving_Image.main(Retrieving_Image.java:24)
错误的说法是:-
Blob b = rs.getBlob(1);
我的智慧。 如果有人能解释这个错误,我们将不胜感激。
【问题讨论】:
-
见这里:stackoverflow.com/a/8349906/330315 读取 blob 只需使用
getBinaryStream()代替