Search code examples
javajdbcresultsetjtdsmssql-jdbc

Why Resultset trimmed?


When referring to the stored procedure client get two Resultset. With the first all is well, but the second consists of 20 rows, client developers claim that the procedure returns about 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() similar 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);
    }
}
  • Database - MSSQL 2000
  • jdbc driver - jtds1.2.5

p.s. Please do not judge strictly junior and sorry for bad english


Solution

  • Problem solved, it turned out went int overflow field. Problem found through via extra logging and exception handling. In my code is not checked exceptions. So guys do not be so stupid as I correctly handle exceptions in your projects