我写了下面的代码:-
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);
我脑子里乱七八糟的。 如果有人能解释错误,我们将不胜感激。
最佳答案
你能试试吗:
((OracleResultSet) rs).getBlob(1);
关于java - 使用 JDBC 获取 BLOB 数据时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21442442/