Why do I get java.lang.AbstractMethodError when trying to load a blob in the db?

JavaOracleJdbc

Java Problem Overview


I've got a problem with JDBC.

I'have the following code:

//blargeparam is a blob column.
PreparedStatement pst =connection.prepareStatement("update gcp_processparams_log set blargeparam= ? where idprocessparamslog=1");

pst.setBinaryStream(1,inputStream);			

I get the following error:

Exception in thread "main" java.lang.AbstractMethodError:           
oracle.jdbc.driver.T2CPreparedStatement.setBinaryStream(ILjava/io/InputStream;)V  

My connection string is jdbc:oracle:oci:@.....

The Oracle version is 11g.

From the error message it seems that something is missing but:

  • when I read from the same blob column (with blob.getBytes) everything works.

  • The DLL's of the instant client are (correctly) in the library path.

  • This is the manifest of the Oracle JDBC JAR in my class path:

     Manifest-Version: 1.0  
     Specification-Title:    Oracle JDBC driver classes for use with JDK14  
     Sealed: true  
     Created-By: 1.4.2_14 (Sun Microsystems Inc.)  
     Implementation-Title:   ojdbc14.jar  
     Specification-Vendor:   Oracle Corporation  
     Specification-Version:  Oracle JDBC Driver version - "10.2.0.4.0"  
     Implementation-Version: Oracle JDBC Driver version - "10.2.0.4.0"  
     Implementation-Vendor:  Oracle Corporation  
     Implementation-Time:    Sat Feb  2 11:40:29 2008  
     		
     		
    

Java Solutions


Solution 1 - Java

With JDBC, that error usually occurs because your JDBC driver implements an older version of the JDBC API than the one included in your JRE. These older versions are fine so long as you don't try and use a method that appeared in the newer API.

I'm not sure what version of JDBC setBinaryStream appeared in. It's been around for a while, I think.

Regardless, your JDBC driver version (10.2.0.4.0) is quite old, I recommend upgrading it to the version that was released with 11g (download here), and try again.

Solution 2 - Java

It looks that even if the driver 10.2 is compatible with the JDBC3 it may not work with JRE6 as I've found here:

http://www.oracle.com/technology/tech/java/sqlj_jdbc/htdocs/jdbc_faq.html#02_03">http://www.oracle.com/technology/tech/java/sqlj_jdbc/htdocs/jdbc_faq.html#02_03</a>

Which JDBC drivers support which versions of Javasoft's JDK?

pre-8i OCI and THIN Drivers - JDK 1.0.x and JDK 1.1.x
8.1.5 OCI and THIN Drivers - JDK 1.0.x and JDK 1.1.x
8.1.6SDK THIN Driver - JDK 1.1.x and JDK 1.2.x (aka Java2)
8.1.6SDK OCI Driver - Only JDK 1.1.x
8.1.6 OCI and THIN Driver - JDK 1.1.x and JDK 1.2.x
8.1.7 OCI and THIN Driver - JDK 1.1.x and JDK 1.2.x
9.0.1 OCI and THIN Driver - JDK 1.1.x, JDK 1.2.x and JDK 1.3.x
9.2.0 OCI and THIN Driver - JDK 1.1.x, JDK 1.2.x, JDK 1.3.x, and JDK 1.4.x
10.1.0 OCI and THIN Driver - JDK 1.2.x, JDK 1.3.x, and JDK 1.4.x
10.2.0 OCI and THIN Driver - JDK 1.2.x, JDK 1.3.x, JDK 1.4.x, and JDK 5.0.x
11.1.0 OCI and THIN Driver - JDK 1.5.x and JDK 1.6.x

Oracle 10.2.0 supports:

Full support for JDBC 3.0
Note that there is no real change in the support for the following in the database. Allthat has changed is that some methods that previously threw SQLException now do something more reasonable instead.
result-set holdability
returning multiple result-sets.

Solution 3 - Java

Here's what the JDK API says about AbstractMethodError:

> Thrown when an application tries to > call an abstract method. Normally, > this error is caught by the compiler; > this error can only occur at run time > if the definition of some class has > incompatibly changed since the > currently executing method was last > compiled.

Bug in the oracle driver, maybe?

Solution 4 - Java

Just put ojdbc6.jar in class path, so that we can fix CallbaleStatement exception:

oracle.jdbc.driver.T4CPreparedStatement.setBinaryStream(ILjava/io/InputStream;J)V)

in Oracle.

Solution 5 - Java

As described in the API of java.sql.PreparedStatement.setBinaryStream() it is available since 1.6 so it is a JDBC 4.0 API! You use a JDBC 3 Driver so this method is not available!

Solution 6 - Java

Just use ojdb6.jar and will fix all such issues.

For maven based applications:

  1. Download and copy ojdbc6.jar to a directory in your local machine

  2. From the location where you have copied your jar install the ojdbc6.jar in your local .M2 Repo by issuing below command C:\SRK\Softwares\Libraries>mvn install:install-file -DgroupId=com.oracle -DartifactId=ojdbc6 -Dversion=11.2.0.3 -Dpackaging=jar -Dfile=ojdbc6.jar -DgeneratePom=true

  3. Add the below in your project pom.xml as ojdbc6.jar dependency

     <dependency>
         <groupId>com.oracle</groupId>
         <artifactId>ojdbc6</artifactId>
         <version>11.2.0.3</version>
     </dependency>
    

PS: The issue might be due to uses of @Lob annotation in JPA for storing large objects specifically in oracle db columns. Upgrading to 11.2.0.3 (ojdbc6.jar) can resolve the issue.

Solution 7 - Java

In my case this was the error.

> Exception in thread "main" java.lang.AbstractMethodError: oracle.jdbc.driver.T4CConnection.isValid(I)Z at org.apache.tomcat.dbcp.dbcp2.DelegatingConnection.isValid(DelegatingConnection.java:917) at org.apache.tomcat.dbcp.dbcp2.PoolableConnection.validate(PoolableConnection.java:282) at org.apache.tomcat.dbcp.dbcp2.PoolableConnectionFactory.validateConnection(PoolableConnectionFactory.java:356) at org.apache.tomcat.dbcp.dbcp2.BasicDataSource.validateConnectionFactory(BasicDataSource.java:2306) at org.apache.tomcat.dbcp.dbcp2.BasicDataSource.createPoolableConnectionFactory(BasicDataSource.java:2289) at org.apache.tomcat.dbcp.dbcp2.BasicDataSource.createDataSource(BasicDataSource.java:2038) at org.apache.tomcat.dbcp.dbcp2.BasicDataSource.getConnection(BasicDataSource.java:1532) at beans.Test.main(Test.java:24)

Solution: I just change ojdbc14.jar to ojdbc6.jar

Solution 8 - Java

I would suggest investigating your classpath very carefully. You might have two different versions of a jar file where one invokes methods in the other and the other method is abstract.

Solution 9 - Java

In my case problem was at context.xml file of my project.

The following from context.xml causes the java.lang.AbstractMethodError, since we didn't show the datasource factory.

<Resource name="jdbc/myoracle"
              auth="Container"
              type="javax.sql.DataSource"
              driverClassName="oracle.jdbc.OracleDriver"
              url="jdbc:oracle:thin:@(DESCRIPTION = ... "
              username="****" password="****" maxActive="10" maxIdle="1"
              maxWait="-1" removeAbandoned="true"/> 

Simpy adding factory="org.apache.tomcat.jdbc.pool.DataSourceFactory" solved the issue:

<Resource name="jdbc/myoracle"
              auth="Container"
              factory="org.apache.tomcat.jdbc.pool.DataSourceFactory"  type="javax.sql.DataSource"
              driverClassName="oracle.jdbc.OracleDriver"
              url="jdbc:oracle:thin:@(DESCRIPTION = ... "
              username="****" password="****" maxActive="10" maxIdle="1"
              maxWait="-1" removeAbandoned="true"/>

To make sure I reproduced the issue several times by removing factory="org.apache.tomcat.jdbc.pool.DataSourceFactory" from Resource

Solution 10 - Java

I do meet this problem. use ojdbc14.jar and jdk 1.6

InputStream in = new FileInputStream(file);		
cstmt.setBinaryStream(1, in,file.length());  // got AbstractMethodError 

InputStream in = new FileInputStream(file);		
cstmt.setBinaryStream(1, in,(int)file.length());  // no problem.

Solution 11 - Java

InputStream in = new FileInputStream(file);     
cstmt.setBinaryStream(1, in,file.length());  

instead of this u need to use

InputStream in = new FileInputStream(file);     
cstmt.setBinaryStream(1, in,(int)file.length());  

Solution 12 - Java

The problem is due to older version of ojdbc - ojdbc14.

Place the latest version of ojdbc jar file in your application or shared library. (Only one version should be there and it should be the latest one) As of today - ojdbc6.jar

Check the application libraries and shared libraries on server.

Solution 13 - Java

I think, the reason of the error from JDBC driver, you should get suitable JDBC driver for your Oracle db. You can get it from

http://www.oracle.com/technetwork/database/enterprise-edition/jdbc-112010-090769.html

Solution 14 - Java

I got the same problem and resolved it.

To resolve this problem, you should upgrade commons-dbcp library to latest version (1.4). It will work with latest JDBC drivers.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questionmic.scaView Question on Stackoverflow
Solution 1 - JavaskaffmanView Answer on Stackoverflow
Solution 2 - Javamic.scaView Answer on Stackoverflow
Solution 3 - JavaSteve B.View Answer on Stackoverflow
Solution 4 - JavaSudarsanView Answer on Stackoverflow
Solution 5 - JavaArne BurmeisterView Answer on Stackoverflow
Solution 6 - JavaShoaib KhanView Answer on Stackoverflow
Solution 7 - JavaMayurChovatiyaView Answer on Stackoverflow
Solution 8 - JavaThorbjørn Ravn AndersenView Answer on Stackoverflow
Solution 9 - JavavalijonView Answer on Stackoverflow
Solution 10 - JavaniwotuView Answer on Stackoverflow
Solution 11 - JavaDhananjay RandiveView Answer on Stackoverflow
Solution 12 - JavaTeddyView Answer on Stackoverflow
Solution 13 - JavaArmağaN OlsuNView Answer on Stackoverflow
Solution 14 - JavaThanhMaiView Answer on Stackoverflow