resultset.getObject上的AbstractMethodError [英] AbstractMethodError on resultset.getObject

查看:2231
本文介绍了resultset.getObject上的AbstractMethodError的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我正在构建一个minecraft插件,插件的一部分从mysql中获取一堆块数据,并在服务器启动时将其加载到缓存中。我有一些在eclipse测试用例中运行正常的代码。但是当我在本地的minecraft服务器中加载插件时,我得到了异常。



 
java.lang.AbstractMethodError:方法com / mysql / jdbc /JDBC4ResultSet.getObject(Ljava/lang/String;Ljava/lang/Class;)Ljava/lang/Object;是抽象
在com.mysql.jdbc.JDBC4ResultSet.getObject(JDBC4ResultSet.java)〜[spigot-1.8.8.jar:git-Spigot-db6de12-d3e0b6f]
在fws.plugins.trigger。 data.ModelDB.loadCollection(ModelDB.java:335)〜[?:?]
在fws.plugins.trigger.database.ModelDB.all(ModelDB.java:295)〜[?:?]
等...





正在抛出的代码。

  rs.getObject(field.getName(),p.fieldType()); 

rs 是一个 java.sql.ResultSet 从排除的查询返回的实例。


p.fieldType()只是返回一个类<?>







稍微更大的代码段...不是它真的显示你的任何东西。如果(field.isAnnotationPresent(Persist.class)){
try {
Persist p = field.getAnnotation( Persist.class);
Object o = rs.getObject(field.getName(),p.fieldType());
field.set(m,p.fieldType()。cast(o));

} catch(Exception e){
// TODO自动生成的catch块
e.printStackTrace();
}
}

我看过网络人说要修复我需要包括ojdbc6.jar并将其用作连接驱动程序。


我将文件添加到文件夹lib下的项目结构中,将其包含在我的项目中,然后将其添加到我的构建文件中。
http://i.imgur.com/7TXLbjj.png
并将连接驱动程序更改为 oracle.jdbc.OracleDriver



同样的问题,似乎不是一个修复。
尽管我已经完成了所有的错误。



任何人都可以帮助我,任何见解等?



编辑**


从命令行

  $ java -version 
java版本1.8.0_51
Java(TM)SE运行时环境(build 1.8.0_51-b16)
Java HotSpot(TM)64位服务器虚拟机(build 25.51-b03,混合模式)


从$

$

  System.out.println(System.getProperty(java.runtime.version)); 

返回1.8.0_51-b16



解决方案

方法 ResultSet.getObject(String columnLabel,Class&T; type) 。看起来您正在使用JDBC 4.0驱动程序,而不是JDBC 4.1(或JDBC 4.2 / Java 8)驱动程序。



您可能需要更新JDBC驱动程序最新的 Connector / J MySQL驱动程序是5.1.38)。


So I'm building a minecraft plugin, one part of the plugin grabs a bunch of block data from mysql and loads it into a cache when the server starts. I have a bit of code that runs fine in eclipse test cases. However when I load the plugin in a local minecraft server the I get the exception.

    java.lang.AbstractMethodError: Method com/mysql/jdbc/JDBC4ResultSet.getObject(Ljava/lang/String;Ljava/lang/Class;)Ljava/lang/Object; is abstract
            at com.mysql.jdbc.JDBC4ResultSet.getObject(JDBC4ResultSet.java) ~[spigot-1.8.8.jar:git-Spigot-db6de12-d3e0b6f]
            at fws.plugins.trigger.database.ModelDB.loadCollection(ModelDB.java:335) ~[?:?]
            at fws.plugins.trigger.database.ModelDB.all(ModelDB.java:295) ~[?:?]
etc...



The bit of code that is throwing the exeption.

rs.getObject( field.getName(), p.fieldType());

rs is a java.sql.ResultSet instance returned from a excuted query.
p.fieldType() just returns a Class<?>



Slightly bigger snippet... not that it really shows you anything else.

if (field.isAnnotationPresent(Persist.class)) {
    try {
        Persist p = field.getAnnotation(Persist.class);
        Object o = rs.getObject( field.getName(), p.fieldType());
        field.set(m,p.fieldType().cast(o));

    } catch (Exception e) {
        // TODO Auto-generated catch block 
        e.printStackTrace();
    } 
}

I have looked online people said to fix I need to include ojdbc6.jar and use it as my Connection Driver.
I added the file to the project structure under a folder lib, included it to my project then added it to my Build File. http://i.imgur.com/7TXLbjj.png and changed the connection driver to oracle.jdbc.OracleDriver

However im getting the same issue, seems like not a fix. Although chances are i have done it all wrong.

Can anyone help me, any insights etc?

EDIT**
from the commandline

$ java -version
java version "1.8.0_51"
Java(TM) SE Runtime Environment (build 1.8.0_51-b16)
Java HotSpot(TM) 64-Bit Server VM (build 25.51-b03, mixed mode)


from Eclipse

System.out.println(System.getProperty("java.runtime.version"));

returns 1.8.0_51-b16



But both are on the same PC, so i would expect the same values?

解决方案

The method ResultSet.getObject(String columnLabel, Class<T> type) was added in JDBC 4.1 (Java 7). It looks like you are using a JDBC 4.0 driver, and not a JDBC 4.1 (or JDBC 4.2/Java 8) driver.

You may need to update your JDBC driver (the latest for Connector/J MySQL driver is 5.1.38).

这篇关于resultset.getObject上的AbstractMethodError的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆