{"record":{"id":"64626a4245a36c55","repo":"pentaho/pentaho-kettle","slug":"error-closing-resultset-after-getting-schemas","errorCode":null,"errorMessage":"Error closing resultset after getting schemas!","messagePattern":"Error closing resultset after getting schemas!","errorType":"exception","errorClass":"KettleDatabaseException","httpStatus":null,"severity":"error","filePath":"core/src/main/java/org/pentaho/di/core/database/Database.java","lineNumber":4524,"sourceCode":"\n  public String[] getSchemas() throws KettleDatabaseException {\n    ArrayList<String> catalogList = new ArrayList<>();\n    ResultSet catalogResultSet = null;\n    try {\n      catalogResultSet = databaseMeta.getSchemas( getDatabaseMetaData() );\n      // Grab all the catalog names and put them in an array list\n      while ( catalogResultSet != null && catalogResultSet.next() ) {\n        catalogList.add( catalogResultSet.getString( 1 ) );\n      }\n    } catch ( SQLException e ) {\n      throw new KettleDatabaseException( \"Error getting schemas!\", e );\n    } finally {\n      try {\n        if ( catalogResultSet != null ) {\n          catalogResultSet.close();\n        }\n      } catch ( SQLException e ) {\n        throw new KettleDatabaseException( \"Error closing resultset after getting schemas!\", e );\n      }\n    }\n\n    if ( log.isDetailed() ) {\n      log.logDetailed( \"read :\" + catalogList.size() + \" schemas from db meta-data.\" );\n    }\n\n    return catalogList.toArray( new String[ catalogList.size() ] );\n  }\n\n  public String[] getCatalogs() throws KettleDatabaseException {\n    ArrayList<String> catalogList = new ArrayList<>();\n    ResultSet catalogResultSet = null;\n    try {\n      catalogResultSet = getDatabaseMetaData().getCatalogs();\n      // Grab all the catalog names and put them in an array list\n      while ( catalogResultSet != null && catalogResultSet.next() ) {\n        catalogList.add( catalogResultSet.getString( 1 ) );","sourceCodeStart":4506,"sourceCodeEnd":4542,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/core/src/main/java/org/pentaho/di/core/database/Database.java#L4506-L4542","documentation":"Thrown in the finally block of getSchemas() when the catalog ResultSet cannot be closed after reading schemas. The schema listing may have succeeded, but cleanup failed — usually a broken connection or driver cursor-close failure. Wrapped as KettleDatabaseException.","triggerScenarios":"Database.getSchemas() where catalogResultSet is non-null but close() throws SQLException — connection dropped between iteration and close, driver cursor invalidated, or concurrent connection use.","commonSituations":"DB session killed during schema listing; network/firewall idle timeout; driver bug closing cursors after a partial metadata failure; sharing the Database object across threads.","solutions":["Ensure the connection is alive before metadata reads; reconnect if checkConnection() fails.","Use a dedicated Database per thread instead of sharing one instance.","Raise firewall/DB idle timeouts for long-running jobs.","Inspect the chained SQLException cause to pinpoint the driver failure."],"exampleFix":"// before\ndb.getSchemas(); // on a connection idle for hours\n\n// after\nif (!db.checkConnection()) { db.disconnect(); db.connect(); }\ndb.getSchemas();","handlingStrategy":"try-catch","validationCode":"if (!db.checkConnection()) { db.disconnect(); db.connect(); }","typeGuard":null,"tryCatchPattern":"try {\n  schemas = db.getSchemas();\n} catch (KettleDatabaseException e) {\n  log.warn(\"Schema resultset close failed: \" + e.getCause());\n  db.disconnect(); db.connect();\n}","preventionTips":["Keep connections alive with keepalives or adequate timeouts","Use one Database instance per thread","Reconnect on stale connections before metadata reads","Inspect cause chain when close() fails"],"tags":["jdbc","database-metadata","resultset","connection"],"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"}