{"record":{"id":"bb8d001e009e87b2","repo":"pentaho/pentaho-kettle","slug":"unable-to-get-table-types-from-database","errorCode":null,"errorMessage":"Unable to get table types from database!","messagePattern":"Unable to get table types from database!","errorType":"exception","errorClass":"KettleDatabaseException","httpStatus":null,"severity":"error","filePath":"core/src/main/java/org/pentaho/di/core/database/Database.java","lineNumber":4176,"sourceCode":"  }\n\n  public RowMetaInterface getReturnRowMeta() {\n    return rowMeta;\n  }\n\n  public String[] getTableTypes() throws KettleDatabaseException {\n    try {\n      ArrayList<String> types = new ArrayList<>();\n\n      ResultSet rstt = getDatabaseMetaData().getTableTypes();\n      while ( rstt.next() ) {\n        String ttype = rstt.getString( \"TABLE_TYPE\" );\n        types.add( ttype );\n      }\n\n      return types.toArray( new String[ types.size() ] );\n    } catch ( SQLException e ) {\n      throw new KettleDatabaseException( \"Unable to get table types from database!\", e );\n    }\n  }\n\n  public String[] getTablenames() throws KettleDatabaseException {\n    return getTablenames( false );\n  }\n\n  public String[] getTablenames( boolean includeSchema ) throws KettleDatabaseException {\n    return getTablenames( null, includeSchema );\n  }\n\n  public String[] getTablenames( String schemanamein, boolean includeSchema ) throws KettleDatabaseException {\n    return getTablenames( schemanamein, includeSchema, null );\n  }\n\n  public String[] getTablenames( String schemanamein, boolean includeSchema, Map<String, String> props )\n    throws KettleDatabaseException {\n    Map<String, Collection<String>> tableMap = getTableMap( schemanamein, props );","sourceCodeStart":4158,"sourceCodeEnd":4194,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/core/src/main/java/org/pentaho/di/core/database/Database.java#L4158-L4194","documentation":"Database.getTableTypes() reads the JDBC DatabaseMetaData table-type list (via getTableTypes/getTables); any SQLException while reading is wrapped in this KettleDatabaseException. It means the database's table-type metadata could not be retrieved.","triggerScenarios":"Calling getTableTypes()/getTablenames() on a connection whose metadata query fails — closed connection, driver not supporting the metadata call, or metadata access denied.","commonSituations":"Calling after db.disconnect(), drivers with incomplete DatabaseMetaData implementations (some embedded/NoSQL bridges), restricted catalog access, or DB session killed between connect and metadata call.","solutions":["Ensure the connection is open (db.connect()) before calling getTableTypes","Inspect the chained SQLException for driver-level metadata support issues","Test with a standard JDBC driver for your database version","Catch KettleDatabaseException and fall back to known defaults (e.g. \"TABLE\",\"VIEW\") when metadata is unavailable"],"exampleFix":"// before\ndb.disconnect();\nString[] types = db.getTableTypes(); // fails\n// after\ndb.connect();\nString[] types = db.getTableTypes();","handlingStrategy":"try-catch","validationCode":"if (db.getConnection() == null || db.getConnection().isClosed()) {\n  db.connect(); // or throw\n}","typeGuard":"boolean metadataReady(Database db) { try { return db.getConnection() != null && !db.getConnection().isClosed(); } catch (SQLException e) { return false; } }","tryCatchPattern":"String[] types;\ntry {\n  types = db.getTableTypes();\n} catch (KettleDatabaseException e) {\n  log.warn(\"Could not read table types, using defaults\", e);\n  types = new String[] { \"TABLE\", \"VIEW\" }; // safe fallback\n}","preventionTips":["Connect before any metadata call and disconnect only at the end","Verify your JDBC driver fully implements DatabaseMetaData","Fallback to standard table types when metadata is restricted","Check DB privileges for catalog/metadata access"],"tags":["jdbc","metadata","database"],"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"}