9

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. https://i.stack.imgur.com/YaVuE.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?

zenril
  • 300
  • 2
  • 8
  • I think there could be JDK issue. Which JDK version are you using in your local machine and which version on server? Please see this post : http://stackoverflow.com/questions/7692320/is-there-really-resultset-getobjectstring-classt-in-jdk7 – Mananpreet Singh Jan 25 '16 at 04:07
  • Seems to be 1.8.0_51 which should be fine and that other answer it dosent relate to my case I dont thnk. – zenril Jan 25 '16 at 05:16
  • Ojdbc16.jar is a driver for oracle db - not for mysql. Check out latest mysql driver at https://dev.mysql.com/downloads/connector/j/ and see if that helps – Jan Jan 25 '16 at 06:34
  • yea whats what i was using :/ – zenril Jan 25 '16 at 06:38
  • its working in eclipse, not in the minecraft enviroment – zenril Jan 25 '16 at 06:42

2 Answers2

8

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

Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
1

Ok Sorry about the Question I have Rethought my approach. Instead of using reflection to set the types of the class members, I have just impletented a method in each data model class that maps ResultSet values to the current object.

@Override
public Select load(ResultSet rs) throws SQLException {
    this.id = rs.getInt("id");
    this.name = rs.getString("name");
    this.uuid = rs.getString("uuid");
    this.chunkX = rs.getInt("chunkX");
    this.chunkZ = rs.getInt("chunkZ");
    this.blockX = rs.getInt("blockX");
    this.blockY = rs.getInt("blockY");
    this.blockZ = rs.getInt("blockZ");
    return this;
};

As for my initial issue using reflection I dont know why it was failing.

zenril
  • 300
  • 2
  • 8