ResultSet在有效结果上返回null

时间:2013-06-20 00:51:03

标签: java sql

我有这样的查询

SELECT 
    COUNT(*) AS TotalAmount
FROM
    CurrentApplications
WHERE
    CurrentApplications.resp_id IN (1)
    AND FinalOutcome_date BETWEEN '2013-04-01 00:00:00' AND '2013-04-30 23:59:59'
    AND (FinalOutcome >= 1 AND FinalOutcome <= 2)
    AND (FIND_IN_SET(14, app_category)
    OR FIND_IN_SET(15, app_category)
    OR FIND_IN_SET(26, app_category))

它在MySQL Workbench中返回值10。

现在我正在重新审查查询:

insideResultsSet = insideStatement
                .executeQuery("SELECT COUNT(*) AS TotalAmount  FROM CurrentApplications  WHERE CurrentApplications.resp_id  IN(1)  AND FinalOutcome_date  BETWEEN '2013-04-01 00:00:00' AND '2013-04-30 23:59:59' AND (FinalOutcome >=1 AND FinalOutcome <= 2)  AND(  FIND_IN_SET(14, app_category) OR  FIND_IN_SET(15, app_category) OR  FIND_IN_SET(26, app_category)) ");
        while (insideResultsSet.next()) 
        {
            mResultValues.put((String)(Reflection("Subdivision_of_land_" + RANGE_NAMES[EachMap.getKey()])),
                    insideResultsSet.getDouble("TotalAmount"));

            Fn.Out(insideResultsSet.getDouble("TotalAmount"));
            Fn.Out_Stop("SELECT COUNT(*) AS TotalAmount "
                    + mCurrentApplications
                    + " WHERE CurrentApplications.resp_id " + mResp_authority + " " + "AND "
                    + FIELD_FinalOutcome_date + " " + EachMap.getValue() + "AND (" + FIELD_FinalOutcome
                    + " >=1 AND " + FIELD_FinalOutcome + " <= " + FIELD_FinalOutComeORRAHighNumber + ") "
                    + getCommaSeachSQL_AppCategory_Multi(new int[]{14,15,26}));
        }

Fn.Out_Stop查询工作率为100%,但直接输出结果时结果甚至无效。

结果为0,对象类型为null。谁能解释一下这里发生了什么?奇怪的错误,因为这对400多个其他查询工作正常..

1 个答案:

答案 0 :(得分:1)

列名可能不是"TotalAmount"。尝试使用索引的getter(如getLong(1))或在查询中的列名称周围加上双引号来强制大小写:

"SELECT COUNT(*) AS \"TotalAmount\" ... "

如果不在查询中引用列名,数据库可以自由更改大小写。