繁体   English   中英

为什么NetBeans Java调试器永远无法到达此代码?

[英]Why does the NetBeans Java debugger never reach this code?

我正在尝试使用NetBeans调试Java中的方法。

该方法是:

    public Integer getNumberOfClamps(Locations paLocation) {
        Integer ret = -1;
        List list = new ArrayList();

        String removeme = "ABC";

        if (paLocation == null) {
            return ret;
        }

        try {
            IO io = new IO(this.getSchemaName());
            Session session = io.getSession();

            String sql = "select count(*) from assets a join assettypes at on (at.id = a.assettype_id) ";
            sql += "where a.currentlocation_id = " + paLocation.getId() + " and at.clamp = 1 and at.active = 1;";
            list = session.createQuery(sql).list();

            // for some reason, list is empty yet MySQL reports 40 records
            // and the following two lines are never reached!
            ret = list.size();
            removeme = "WHAT???";

        } catch (Exception ex) {
            ret = -1;  // explicitly set return
        } finally {
            return ret;
        }
    }

在方法中间,您将看到list = session.createQuery(sql).list();

出于某种原因,即使手动运行SQL,我也会得到40个结果,这将返回一个空列表。

但是奇怪的是,一旦调用.list() ,它就会跳到finally块,而永远不会到达其余块! 所以对于测试,“removeme”应该等于WHAT??? 但是调试器报告它仍然是ABC

是什么赋予了?

您使用了错误的方法。 'createQuery'需要HQL语法。 将您的方法更改为“ createSQLQuery”

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM