2

I wrote the following code:-

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();

    }
}

In the above code I'm trying to retrieve an image which is in the 1st index of first row of the resultset, in fact the resultset has only one row. But I am getting the following error:-

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)

With the erroneous statement being:-

Blob b = rs.getBlob(1);

Out of my wits. It will be greatly appreciated if someone could explain the error.

1
  • See here: stackoverflow.com/a/8349906/330315 to read a blob just use getBinaryStream() instead Commented Jan 29, 2014 at 21:47

2 Answers 2

0

Could you try :

((OracleResultSet) rs).getBlob(1);
Sign up to request clarification or add additional context in comments.

1 Comment

@fisc OracleResultSet cannot be resolved to a type
0

By selecting "star" or "*" in

"select * from picture"

You are not specifying the column order, and as such, there is no guarantee that the blob will be the first column in the ResultSet. Remove the star from the select statement, and try again with a comma separated list of the columns you care about. Then you will be certain that you are selecting the right data type at the specified index.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.