6

I already read Why do I get java.lang.AbstractMethodError when trying to load a blob in the db?, downloaded all of the 11g jdbc drivers I could find, and added them as libraries and/or jar files to my NetBeans application. I still keep getting the same AbstractMethodError and it is driving me batty! Any guidance would be greatly appreciated!

try {

    stmt = conn.createStatement();
    inputFileInputStream = new FileInputStream(inputBinaryFile);  

    Blob vBlob = conn.createBlob();
    BufferedImage vGImage=ImageIO.read(name);
    int offset =0;
    OutputStream out = vBlob.setBinaryStream(offset);
    ImageIO.write(vGImage, "JPG", out);
    PreparedStatement stat = conn.prepareStatement("INSERT INTO item VALUES (?,?,?,?,?)");
    stat.setString(1, itemNo);
    stat.setString(2, itemName);
    stat.setBlob(3,vBlob);
    stat.setString(4, invenType);
    stat.setDouble(5, vPrice);
    stat.executeUpdate();

} catch (IOException e) {
    System.out.println("Caught I/O Exception: (Write BLOB value - Put Method).");
    e.printStackTrace();
    throw e;
} catch (SQLException e) {
    System.out.println("Caught SQL Exception: (Write BLOB value - Put Method).");
    System.out.println("SQL:\n" + sqlText);
    e.printStackTrace();
    throw e;
}finally {
    conn.close();
}  

The error message:

Exception in thread "main" java.lang.AbstractMethodError:                        
oracle.jdbc.driver.OracleConnection.createBlob()Ljava/sql/Blob;
    at DatabaseIO.setOracleDBBlob(DatabaseIO.java:115)
    at DatabaseIO.main(DatabaseIO.java:26)
isapir
  • 21,295
  • 13
  • 115
  • 116
Mike
  • 1,590
  • 8
  • 27
  • 41
  • 1
    You already read the other question, but I don't see anything that makes this question _not_ a dup. – Matt Ball May 20 '11 at 01:42
  • 6
    first things first: make sure your classpath only contains the required JDBC 4.0 drivers for oracle, not any earlier drivers – Jochen Bedersdorfer May 20 '11 at 01:48
  • 1
    possible duplicate of [Why do I get java.lang.AbstractMethodError when trying to load a blob in the db?](http://stackoverflow.com/questions/1194990/why-do-i-get-java-lang-abstractmethoderror-when-trying-to-load-a-blob-in-the-db) – user207421 May 20 '11 at 04:36

2 Answers2

11

The cause of the problem is incompatible software (jar files).

createBlob is a new method (introduced in java 1.6), so older drivers are very unlikely to implement it.

Make sure your classpath only contains compatible drivers, and not any earlier versions of the drivers. (Thanks Jochen)

Klas Lindbäck
  • 33,105
  • 5
  • 57
  • 82
  • 2
    thanks, thanks, thanks, thanks, thanks, thanks, thanks, thanks, thanks, thanks, thanks, thanks, thanks, thanks sorry that you got just +1 right now I am in the mood for +100 :) – elrado Mar 20 '14 at 11:45
5

As others have said this is due to an older Oracle JDBC driver.

In my case replacing ojdbc14.jar (Oracle JDBC driver 10.1.0.5.0) with ojdbc16.jar (Oracle JDBC driver 11.2.0.4.0) fixed the problem.

isapir
  • 21,295
  • 13
  • 115
  • 116
  • I am not sure if `ojdbc16.jar` is correct or it is a typo. I found a jar named `ojdbc6.jar` (with version 11.2.0.4), and it solved the problem. – luca.vercelli Sep 29 '20 at 09:27