1

I have written a code that will help the user to save the image in the oracle database using JDBC.

PreparedStatement ps =con.prepareStatement("insert into employee values(?,?)");
ps.setString(1,name);
ps.setBlob(2,inputStream);

But when I am trying to run the code,it is getting an error

java.lang.AbstractMethodError: Method oracle/jdbc/driver/T4CPreparedStatement.setBlob(ILjava/io/InputStream;)V is abstract

How is this caused and how can I solve it?

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
Sampad
  • 1,645
  • 11
  • 14
  • That error almost always means that you are using different versions of a library (in this case, the JDBC driver or support library). – chrylis -cautiouslyoptimistic- Feb 08 '17 at 06:59
  • @AxelH, thanks, but I have downloaded ojdbc6.jar but it was not working too. I have also tried to use `setBinaryStream`, still i am facing the same issue. – Sampad Feb 08 '17 at 07:20
  • @Sampad, what is your JDK version ? Since no JDBC for oracle 10g support JDK 6, 7 or 8, I wonder if it could come from there... – AxelH Feb 08 '17 at 07:26
  • @AxelH My JDK version is 1.8 and using Oracle 10g as the database. – Sampad Feb 08 '17 at 07:38
  • @Sampad since it is not official supported, I would check quickly with a supported JDK to remove this possibility (JDK 5 is the latest for jdbc 14 ...) – AxelH Feb 08 '17 at 07:41
  • Thanks @AlexH please help me so that I can resolve the issue. – Sampad Feb 08 '17 at 07:43
  • Following [archived JDBC FAQ](https://web.archive.org/web/20100619183653/http://www.oracle.com/technology/tech/java/sqlj_jdbc/htdocs/jdbc_faq.html#02_02) you can use the ojdbc driver from the Oracle 11/12 with Oracle 10. Have a look at [current JDBC FAQ](http://www.oracle.com/technetwork/database/enterprise-edition/jdbc-faq-090281.html#01_02) for a driver. Check also that there is no older ojdbc driver in your classpath. – SubOptimal Feb 08 '17 at 07:59

1 Answers1

-1

Try converting your inputStream to byte[] first and pass it as the parameter to the steBlob method

eg :

BufferedInputStream bis= new BufferedInputStream(inputStream); /// pass your inputStream here
        int size=0;
        byte[] bytes;
        Blob blob = con.createBlob(); // create blob using connection obj
        int length = 1;
        int readCount=0;
        System.out.println(img.getCanonicalPath());
        do {
            bytes = new byte[bis.available()];
            readCount = bis.read(bytes);
            blob.setBytes(length, bytes); ///populate chunks of data to the blob
            length=length+readCount;

            size= bis.available();
            //System.out.println(bis.read());
        }while ( size > 0 );
        PreparedStatement st = con.prepareStatement("INSERT INTO TABLE VALUES (?,?)");
        st.setString(1, id);
        st.setBlob(2, blob);
        st.execute();
ABHIJITH GM
  • 134
  • 4