1

我将 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)

谁能告诉我为什么会出现这个异常以及如何处理。

我使用这个返回的结果集的代码是:

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

              }
          }
      }

提前致谢。

4

1 回答 1

3

closeOnCompletion()自 Java 7 以来就存在。驱动程序已使用以前版本的接口实现。所以这个方法不是MySQL驱动实现的。

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

于 2012-06-06T07:20:27.983 回答