{"record":{"id":"d655fc84d27eabc6","repo":"pentaho/pentaho-kettle","slug":"error-closing-resultset-after-getting-views-from-schema","errorCode":null,"errorMessage":"Error closing resultset after getting views from schema []","messagePattern":"Error closing resultset after getting views from schema \\[\\]","errorType":"exception","errorClass":"KettleDatabaseException","httpStatus":null,"severity":"error","filePath":"core/src/main/java/org/pentaho/di/core/database/Database.java","lineNumber":4288,"sourceCode":"\n              if ( tableProperty.equals( propValue ) ) {\n                multimapPut( schema, table, tableMap );\n              }\n            }\n          }\n        } else {\n          multimapPut( schema, table, tableMap );\n        }\n      }\n    } catch ( SQLException e ) {\n      log.logError( \"Error getting tablenames from schema [\" + schemaname + \"]\" );\n    } finally {\n      try {\n        if ( alltables != null ) {\n          alltables.close();\n        }\n      } catch ( SQLException e ) {\n        throw new KettleDatabaseException( \"Error closing resultset after getting views from schema [\"\n          + schemaname + \"]\", e );\n      }\n    }\n\n    if ( log.isDetailed() ) {\n      log.logDetailed( \"read :\" + multimapSize( tableMap ) + \" table names from db meta-data.\" );\n    }\n\n    return tableMap;\n  }\n\n  public String[] getViews() throws KettleDatabaseException {\n    return getViews( false );\n  }\n\n  public String[] getViews( boolean includeSchema ) throws KettleDatabaseException {\n    return getViews( null, includeSchema );\n  }","sourceCodeStart":4270,"sourceCodeEnd":4306,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/core/src/main/java/org/pentaho/di/core/database/Database.java#L4270-L4306","documentation":"Thrown by Database.getTableMetaData-style schema table/view enumeration when the JDBC ResultSet holding the view names cannot be closed in the finally block. The view listing itself may have succeeded, but cleanup failed, so Kettle wraps the SQLException in a KettleDatabaseException. It usually indicates a broken connection or driver-level cursor close failure.","triggerScenarios":"Calling Database.getViews(...)/getTableMap-style metadata enumeration where connection.alltables (the ResultSet from getDatabaseMetaData().getTables) is non-null but rs.close() throws SQLException — typically because the connection was already closed or the driver dropped it.","commonSituations":"Connection killed by firewall/DB timeout before metadata reads finish; Oracle/MySQL driver cursor close failure on stale connections; concurrent use of one Database connection from multiple threads; calling getViews after disconnect().","solutions":["Check/verify the DB connection is still alive before metadata calls (connection healthy, not timed out).","Ensure only one thread uses the Database instance; synchronize or create one Database per thread.","Increase firewall/idle timeout or enable JDBC keepalive so the connection survives metadata queries.","Upgrade the JDBC driver; some drivers throw on closing already-invalidated cursors."],"exampleFix":"// before\nDatabase db = new Database(meta);\ndb.connect();\nList<String> views = db.getViews(false, null); // later, connection already stale\n\n// after\nDatabase db = new Database(meta);\ndb.connect();\nif (!db.checkConnection()) { db.disconnect(); db.connect(); }\nList<String> views = db.getViews(false, null);","handlingStrategy":"try-catch","validationCode":"if (!db.checkConnection()) { db.disconnect(); db.connect(); }","typeGuard":"boolean connectionAlive(Database db) { return db != null && db.getConnection() != null; }","tryCatchPattern":"try {\n  views = db.getViews(false, schema);\n} catch (KettleDatabaseException e) {\n  log.warn(\"View metadata read/close failed, reconnecting: \" + e.getMessage());\n  db.disconnect(); db.connect();\n  views = db.getViews(false, schema);\n}","preventionTips":["Verify connection liveness before long metadata operations","Never share a Database object across threads","Keep JDBC drivers up to date","Configure DB/firewall idle timeouts larger than job duration"],"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"}