{"record":{"id":"bef8c838ef24c28e","repo":"pentaho/pentaho-kettle","slug":"unable-to-check-if-table-0-exists-on-connection-1","errorCode":null,"errorMessage":"Unable to check if table [{0}] exists on connection [{1}].","messagePattern":"Unable to check if table \\[(.+?)\\] exists on connection \\[(.+?)\\]\\.","errorType":"exception","errorClass":"KettleDatabaseException","httpStatus":null,"severity":"error","filePath":"core/src/main/java/org/pentaho/di/core/database/Database.java","lineNumber":2233,"sourceCode":"  @Deprecated\n  public boolean checkTableExistsByDbMeta( String schema, String tablename ) throws KettleDatabaseException {\n    boolean isTableExist = false;\n    if ( log.isDebug() ) {\n      log.logDebug( BaseMessages.getString( PKG, \"Database.Info.CheckingIfTableExistsInDbMetaData\", tablename ) );\n    }\n    try ( ResultSet resTables = getTableMetaData( schema, tablename ) ) {\n      while ( resTables.next() ) {\n        String resTableName = resTables.getString( TABLES_META_DATA_TABLE_NAME );\n        if ( tablename.equalsIgnoreCase( resTableName ) ) {\n          if ( log.isDebug() ) {\n            log.logDebug( BaseMessages.getString( PKG, \"Database.Info.TableFound\", tablename ) );\n          }\n          isTableExist = true;\n          break;\n        }\n      }\n    } catch ( SQLException e ) {\n      throw new KettleDatabaseException(\n        BaseMessages.getString( PKG, \"Database.Error.UnableToCheckExistingTable\", tablename, databaseMeta.getName() ),\n        e );\n    }\n    return isTableExist;\n  }\n\n  /**\n   * Retrieves the table description matching the schema and table name.\n   *\n   * @param schema the schema name pattern\n   * @param table  the table name pattern\n   * @return table description row set\n   * @throws KettleDatabaseException if DatabaseMetaData is null or some database error occurs\n   */\n  private ResultSet getTableMetaData( String schema, String table ) throws KettleDatabaseException {\n    ResultSet tables = null;\n    if ( getDatabaseMetaData() == null ) {\n      throw new KettleDatabaseException( BaseMessages.getString( PKG, \"Database.Error.UnableToGetDbMeta\" ) );","sourceCodeStart":2215,"sourceCodeEnd":2251,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/core/src/main/java/org/pentaho/di/core/database/Database.java#L2215-L2251","documentation":"Thrown by Database.checkTableExists(tablename) (the DatabaseMetaData.getTables-based variant) when SQLException occurs while enumerating tables. The message is localized via the messages bundle key Database.Error.UnableToCheckExistingTable with the table and connection name as parameters.","triggerScenarios":"Database.checkTableExists(...) when databaseMeta.getTables(...)/getDatabaseMetaData().getTables() throws SQLException — connection broken, catalog/schema-access permission denied, driver error.","commonSituations":"User lacking permission to list tables in the schema/catalog; wrong schema parameter so metadata calls fail; connection dropped before the metadata call.","solutions":["Check the SQLException cause for a permissions or connectivity error","Confirm the connected user can read the schema's table catalog (e.g. GRANT SELECT on catalog views)","Pass the correct schema/catalog name; use the schema-argument overload","Fall back to tableExists(...) probe or catch and handle gracefully"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"if (!database.isOpened()) throw new IllegalStateException(\"Connect before checkTableExists\");","typeGuard":null,"tryCatchPattern":"try {\n  boolean exists = database.checkTableExists(schema, tablename);\n} catch (KettleDatabaseException e) {\n  Throwable cause = e.getCause();\n  if (cause instanceof SQLException && cause.getMessage().contains(\"permission\")) {\n    throw new SecurityException(\"Cannot read catalog for \" + schema, cause);\n  }\n  throw e;\n}","preventionTips":["Grant catalog/metadata read privileges to the connection user","Pass correct schema/catalog arguments","Use consistent identifier casing","Retry on transient connectivity SQLExceptions"],"tags":["database","metadata","table-exists"],"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"}