Search code examples
javajdbcdb2db2-luw

Java Connection.setClientInfo results AbstractMethodError


It is simple Java code that sets client information (ClientHostname) to java.sql.Connection. But it is giving java.lang.AbstractMethodError: com.ibm.db2.jcc.t4.b.setClientInfo(Ljava/lang/String;Ljava/lang/String;)V error. Any one has any idea what went wrong? I am using java 8.

I could not find the route cause for this. Casting to DB2Connection also did not help.

public class Main {
  public static void main(String[] args) {
    try {
      Class.forName("com.ibm.db2.jcc.DB2Driver");
      Connection con = DriverManager.getConnection("jdbc:db2://host:port/db", "user", "pwd");
      con.setClientInfo("ClientHostname", "localhost"); // => error here
      System.out.println("SUCCEED  setting ClientHostname");
    } catch (Exception ex) {
        ex.printStackTrace();
    }
  }
}

Solution

  • setClientInfo is a JDBC 4.0 method, so you need to be using the JDBC 4.0 driver.

    IBM provides a JDBC 3.0 driver in db2jcc.jar, and JDBC 4.0 driver in db2jcc4.jar. So, make sure you have db2jcc4.jar in your CLASSPATH and not db2jcc.jar.