{"record":{"id":"7ec6c4418c49c128","repo":"pentaho/pentaho-kettle","slug":"unable-to-get-list-of-rows-from-resultset","errorCode":null,"errorMessage":"Unable to get list of rows from ResultSet : ","messagePattern":"Unable to get list of rows from ResultSet : ","errorType":"exception","errorClass":"KettleDatabaseException","httpStatus":null,"severity":"error","filePath":"core/src/main/java/org/pentaho/di/core/database/Database.java","lineNumber":4099,"sourceCode":"          } else {\n            stop = true;\n          }\n          if ( monitor != null && limit > 0 ) {\n            monitor.worked( 1 );\n          }\n          if ( monitor != null && monitor.isCanceled() ) {\n            break;\n          }\n        }\n        closeQuery( rset );\n        if ( monitor != null ) {\n          monitor.done();\n        }\n      }\n\n      return result;\n    } catch ( Exception e ) {\n      throw new KettleDatabaseException( \"Unable to get list of rows from ResultSet : \", e );\n    }\n  }\n\n  /**\n   * Iterates over the first 'limit' rows of the ResultSet obtained from the given SQL statement,\n   * executing the given callback for each row. If limit <= 0, all rows are processed.\n   *\n   * @param sql      The SQL statement to execute\n   * @param limit    The maximum number of rows to process (<=0 means unlimited)\n   * @param callback The callback to execute for each row (receives Object[] row)\n   * @throws KettleDatabaseException if something goes wrong\n   */\n  public void forEachRow( String sql, int limit, java.util.function.Consumer<Object[]> callback )\n    throws KettleDatabaseException {\n    try ( ResultSet rset = openQuery( sql ) ) {\n      int count = 0;\n      while ( rset != null && ( limit <= 0 || count < limit ) ) {\n        Object[] row = getRow( rset );","sourceCodeStart":4081,"sourceCodeEnd":4117,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/core/src/main/java/org/pentaho/di/core/database/Database.java#L4081-L4117","documentation":"A Database method iterating a ResultSet into a List<Object[]> caught an unexpected Exception while reading rows and rethrew it as a KettleDatabaseException with this generic message and the cause chained. The real reason is in 'e' — a fetch, conversion, or connection failure mid-read.","triggerScenarios":"getRows(...)/getFirstRows(...) loops over rs.next()/getRow() that fail partway — connection dropped during iteration, JDBC type conversion error, or interrupted fetch with a monitor.","commonSituations":"Long-running result sets losing connection mid-read, driver unable to convert exotic column types to Kettle values, huge result sets hitting memory/timeouts, or cancelled statements.","solutions":["Inspect the chained cause for the concrete driver error","Limit rows fetched (getFirstRows with a limit, add WHERE/LIMIT to the SQL)","Check connection network stability and socket timeouts for long reads","Verify the column types are convertible; CAST problematic columns in SQL"],"exampleFix":"// before\nList<Object[]> rows = db.getRows(sql, null); // millions of rows\n// after\nList<Object[]> rows = db.getRows(sql, 10000); // bounded fetch via getFirstRows-style limit","handlingStrategy":"try-catch","validationCode":"// limit work up front and verify connectivity\nif (!db.getConnection().isValid(5)) throw new IllegalStateException(\"connection dead before getRows\");\nint limit = 1000; // prefer getFirstRows(sql, limit)","typeGuard":"null","tryCatchPattern":"try {\n  List<Object[]> rows = db.getRows(sql, numRows);\n} catch (KettleDatabaseException e) {\n  Throwable c = e.getCause();\n  if (c instanceof java.net.SocketTimeoutException || (c != null && c.getMessage() != null && c.getMessage().contains(\"Connection\"))) {\n    // reconnect & retry once\n  }\n  throw e;\n}","preventionTips":["Always bound result sets (limits, WHERE clauses) to avoid long fragile fetches","Increase socket/network timeouts for large reads","CAST non-standard column types in SQL before fetching","Retry idempotent reads on transient connection failures"],"tags":["jdbc","resultset","data-conversion"],"backgroundTag":"database-query-failed","analyzedSha":"f3058517a153da500bf4551f46d79b91bf8ec552","analyzedAt":"2026-09-13T14:04:16.340Z","contentChangedAt":"2026-09-13T14:04:16.340Z","schemaVersion":2},"datasetVersion":"2026-09-20T23:17:15.980Z"}