为什么要修剪Resultset?

时间:2014-06-10 15:05:34

标签: java jdbc resultset jtds mssql-jdbc

当引用存储过程时,客户端获取两个Resultset。第一个很好,但第二个包含20行,客户端开发人员声称该过程返回大约1000行。

Connect connectObject = new Connect();
Connection connectionToPool = null;
CallableStatement procedure = null;
ResultSet table = null;
int rowCounter;
SOATO answer = new SOATO();
int counter = 1;

try {
    connectObject.init(POOL);
    connectionToPool = connectObject.getConnection();

    procedure = connectionToPool.prepareCall("{call procedure()}");
    procedure.execute();

    while (true) {
        rowCounter = procedure.getUpdateCount();

        if (rowCounter > 0) {             // This  is update counter
            procedure.getMoreResults();
            continue;
        }

        if (rowCounter == 0) {   // DDL command or 0 updates
            procedure.getMoreResults();
            continue;
        }

        table = procedure.getResultSet();     // If we reached here, we have a    
                                             //   set of data, or no more results
        if (table != null) {
            switch (counter) {
                case 1:                 // Area tables
                    answer.areaDataHandler(table);
                    counter++;
                    break;

                case 2:                // Region tables
                    answer.regionDataHandler(table);
                    counter++;
                    break;

                default:
                    break;
            }
            procedure.getMoreResults();
            continue;
        }
        break;                              // No more results
    }
    } catch (SQLException e) {
        e.toString();
    } finally {
        if (table != null) {
            try {
                table.close();
            } catch (SQLException e) {
                e.toString();
            }
        }
        if (procedure != null) {
            try {
                procedure.close();
            } catch (SQLException e) {
                e.toString();
            }
        }
        if (connectionToPool != null) {
            connectObject.releaseConnection(connectionToPool);
        }
    }
    return answer;
}

regionDataHandler()类似areaDataHandler()

public void areaDataHandler(ResultSet table) throws SQLException {

    while (table.next()) {
        Area temp = new Area();
        temp.setKodobl(table.getInt("kodobl"));
        temp.setNameobl(table.getString("nameobl"));
        area.add(temp);
    }
}
  • 数据库 - MSSQL 2000
  • jdbc driver - jtds1.2.5

P.S。 请不要严格判断大三和抱歉英语不好

1 个答案:

答案 0 :(得分:0)

问题解决了,原来是int溢出字段。 通过额外的日志记录和异常处理找到问题。 在我的代码中没有检查异常。 因此,在我正确处理项目中的异常时,伙计们并不是那么愚蠢