尝试在数据库中加载 blob 时,为什么会出现 java.lang.AbstractMethodError 错误?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1194990/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-12 00:46:14  来源:igfitidea点击:

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

javadatabaseoraclejdbcoracleclient

提问by mic.sca

I've got a problem with JDBC.

我遇到了 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:@.....

我的连接字符串是 jdbc:oracle:oci:@.....

The Oracle version is 11g.

Oracle 版本是 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  
    
  • 当我从同一个 blob 列(使用 blob.getBytes)读取时,一切正常。
  • 即时客户端的 DLL(正确)位于库路径中。
  • 这是我的类路径中 Oracle JDBC JAR 的清单:

    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  
    

采纳答案by mic.sca

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:

看起来即使驱动程序 10.2 与 JDBC3 兼容,它也可能不适用于 JRE6,因为我在这里发现:

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

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

哪些 JDBC 驱动程序支持哪些版本的 Javasoft 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

8i 之前的 OCI 和 THIN 驱动程序 - JDK 1.0.x 和 JDK 1.1.x
8.1.5 OCI 和 THIN 驱动程序 - JDK 1.0.x 和 JDK 1.1.x
8.1.6SDK THIN 驱动程序 - JDK 1.1.x 和 JDK 1.2.x(又名 Java2)
8.1.6SDK OCI 驱动程序 - 只有 JDK 1.1.x
8.1.6 OCI 和 THIN 驱动程序 - JDK 1.1.x 和 JDK 1.2.x
8.1.7 OCI 和 THIN 驱动程序 - JDK 1.1.x 和 JDK 1.2.x
9.0。 1 OCI 和 THIN 驱动程序 - JDK 1.1.x、JDK 1.2.x 和 JDK 1.3.x
9.2.0 OCI 和 THIN 驱动程序 - JDK 1.1.x、JDK 1.2.x、JDK 1.3.x 和 JDK 1.4.x
10.1。 0 OCI 和 THIN 驱动程序 - JDK 1.2.x、JDK 1.3.x 和 JDK 1.4.x
10.2.0 OCI 和 THIN 驱动程序 - JDK 1.2.x、JDK 1.3.x、JDK 1.4.x 和 JDK 5.0.x
11.1 .0 OCI 和 THIN 驱动程序 - JDK 1.5.x 和 JDK 1.6.x

Oracle 10.2.0 supports:

Oracle 10.2.0 支持:

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.

完全支持 JDBC 3.0
请注意,数据库中对以下内容的支持没有真正的变化。所有改变的是以前抛出 SQLException 的一些方法现在做了更合理的事情。
结果集可保存性
返回多个结果集。

回答by Steve B.

Here's what the JDK API says about AbstractMethodError:

以下是 JDK API 关于 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?

oracle 驱动程序中的错误,也许?

回答by Thorbj?rn Ravn Andersen

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.

我建议非常仔细地调查您的类路径。您可能有两个不同版本的 jar 文件,其中一个调用另一个中的方法,另一个方法是抽象的。

回答by skaffman

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.

对于 JDBC,发生该错误的原因通常是您的 JDBC 驱动程序实现的 JDBC API 版本比 JRE 中包含的版本旧。只要您不尝试使用出现在较新 API 中的方法,这些旧版本就可以了。

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

我不确定 JDBCsetBinaryStream出现在哪个版本中。我想它已经存在一段时间了。

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.

无论如何,您的JDBC驱动程序版本(10.2.0.4.0)已经很旧了,我建议将其升级到11g发布的版本(在此处下载),然后再试一次。

回答by Arne Burmeister

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 Driverso this method is not available!

如 API 中所述,java.sql.PreparedStatement.setBinaryStream()它从 1.6 开始可用,因此它是JDBC 4.0 API!您使用JDBC 3 驱动程序,因此此方法不可用!

回答by Sudarsan

Just put ojdbc6.jarin class path, so that we can fix CallbaleStatementexception:

只需放入ojdbc6.jar类路径,以便我们可以修复CallbaleStatement异常:

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

in Oracle.

在甲骨文。

回答by niwotu

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

我确实遇到了这个问题。使用 ojdbc14.jar 和 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.

回答by ThanhMai

I got the same problem and resolved it.

我遇到了同样的问题并解决了它。

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

要解决此问题,您应该将commons-dbcp库升级到最新版本 (1.4)。它将与最新的 JDBC 驱动程序一起使用。

回答by Dhananjay Randive

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

回答by Shoaib Khan

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

只需使用 ojdb6.jar 即可解决所有此类问题。

For maven based applications:

对于基于 maven 的应用程序:

  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>
    
  1. 下载 ojdbc6.jar 并将其复制到本地机器的目录中

  2. 从您复制 jar 的位置,通过发出以下命令 C:\SRK\Softwares\Libraries>mvn install:install-file -DgroupId=com.oracle -DartifactId=ojdbc6 - 在本地 .M2 Repo 中安装 ojdbc6.jar - Dversion=11.2.0.3 -Dpackaging=jar -Dfile=ojdbc6.jar -DgeneratePom=true

  3. 在您的项目 pom.xml 中添加以下内容作为 ojdbc6.jar 依赖项

    <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.

PS:问题可能是由于在 JPA 中使用 @Lob 注释来专门在 oracle db 列中存储大对象。升级到 11.2.0.3 (ojdbc6.jar) 可以解决该问题。