如何处理java.lang.AbstractMethodError:com.mysql.jdbc.JDBC4CallableStatement.closeOnCompletion()

时间:2012-06-06 07:16:54

标签: java

我正在使用mysql-connector-java-5.1.20-bin.jar和jdk7以及tomcat7,但我的代码在执行callableStatement.closeOnCompletion()时给出了abstractMethodError。代码如下:

尝试{

    Session session = HibernateUtil.currentSession();
    CallableStatement st = session.connection().prepareCall(
    "{call getOfflineNodes('" + strDevice + "',"
    + System.currentTimeMillis() + "," + polltime + ","+ status + ")}");
    ResultSet rs = st.executeQuery();
    Transaction tx = session.beginTransaction();
    st.closeOnCompletion();
    tx.commit();
    HibernateUtil.closeSession();
    return rs;
}

并完成例外:

java.lang.AbstractMethodError: com.mysql.jdbc.JDBC4CallableStatement.closeOnCompletion()V
at com.clearcube.util.DMLLayer.getOfflineNodes(DMLLayer.java:90)
at com.clearcube.logging.ShutBladeAlertService.<init>(ShutBladeAlertService.java:80)
at com.clearcube.common.CMSServiceLoaderServlet.init(CMSServiceLoaderServlet.java:95)
at javax.servlet.GenericServlet.init(GenericServlet.java:160)
at org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:1266)
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1185)
at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1080)
at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:5015)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5302)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1566)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1556)
at java.util.concurrent.FutureTask$Sync.innerRun(Unknown Source)
at java.util.concurrent.FutureTask.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)

任何人都可以告诉我为什么会出现这种异常以及如何解决这个问题。

我正在使用此返回的resultSet的代码是:

timer.scheduleAtFixedRate(new TimerTask() {
          public void run()
          {
            String bladeMacs = "";
            String vmMacs = "";
            try
            {
              int poll = Integer.parseInt(
                ServerConfigurationService.getProperty("blade.refresh.time"));

              Calendar callendar = Calendar.getInstance();

              String strblade = "";
              String strvm = "";
              String Ip = "";
              ResultSet BladeRs = (ResultSet)DMLLayer.getOfflineNodes(
                "Blade", poll, 1);
              if (BladeRs != null) {
                boolean isBladeAlive = false;
                int x = 0;
                try {
                  while (BladeRs.next()) {

                    String mac = BladeRs.getString("macAddress");
                    String ip = BladeRs.getString("Ip");
                    isBladeAlive = 
                      EchoUDPClientDiscoveryObjectResponse.echo(InetAddress.getByName(BladeRs
                      .getString("Ip")), 6502, "any", 
                      3, 500);

                    if (!isBladeAlive) {

                      if (x > 0)
                      {
                        strblade = strblade + "\n";
                        bladeMacs = bladeMacs + "\n";
                      }

                      strblade = strblade + ip;
                      x = 2;
                      bladeMacs = bladeMacs + mac;
                    }
                    else
                    {
                        String query = "update DiscoveredNode set DateModified=:DateModified where MacAddress=:MacAddress";

                      ShutBladeAlertService.objTypeVector.removeAllElements();
                      ShutBladeAlertService.objFieldVector.removeAllElements();
                      ShutBladeAlertService.objValueVector.removeAllElements();

                      ShutBladeAlertService.objTypeVector.add("Long");
                      ShutBladeAlertService.objFieldVector.add("DateModified");
                      ShutBladeAlertService.objValueVector.add(
                        Long.valueOf(System.currentTimeMillis()));
                      ShutBladeAlertService.objTypeVector.add("String");
                      ShutBladeAlertService.objFieldVector.add("MacAddress");
                      ShutBladeAlertService.objValueVector.add(mac);

                      DMLLayer.runUpdateQuery(query, 
                        ShutBladeAlertService.objFieldVector, ShutBladeAlertService.objValueVector, 
                        ShutBladeAlertService.objTypeVector);
                    }
                  }

                  BladeRs.close();

                }
                catch (Exception ex1) {
                  ex1.printStackTrace();
                }

              }
          }
      }

提前致谢。

1 个答案:

答案 0 :(得分:3)

自Java 7以来,

closeOnCompletion()已存在。并且该驱动程序已使用以前版本的接口实现。所以这个方法不是由MySQL驱动程序实现的。

查找是否存在支持此方法的更新版本(但似乎不存在),或者避免调用此方法。