BLOB數據我寫了下面的代碼: -錯誤而獲取使用JDBC
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);
從我不知所措。 如果有人能解釋錯誤,我們將不勝感激。
,請參閱:http://stackoverflow.com/a/8349906/330315讀取BLOB只是使用'getBinaryStream()'代替 –