{"record":{"id":"a26508f4a16b8184","repo":"pentaho/pentaho-kettle","slug":"unable-to-check-if-column-columnname-exists-in-table","errorCode":null,"errorMessage":"Unable to check if column [\" + columnname + \"] exists in table [\" + tablename + \"] on connection [\" + databaseMeta.getName() + \"]","messagePattern":"Unable to check if column \\[\" \\+ columnname \\+ \"\\] exists in table \\[\" \\+ tablename \\+ \"\\] on connection \\[\" \\+ databaseMeta\\.getName\\(\\) \\+ \"\\]","errorType":"exception","errorClass":"KettleDatabaseException","httpStatus":null,"severity":"error","filePath":"core/src/main/java/org/pentaho/di/core/database/Database.java","lineNumber":2362,"sourceCode":"   */\n  @Deprecated\n  public boolean checkColumnExists( String columnname, String tablename ) throws KettleDatabaseException {\n    try {\n      if ( log.isDebug() ) {\n        log.logDebug( \"Checking if column [\" + columnname + \"] exists in table [\" + tablename + \"] !\" );\n      }\n\n      // Just try to read from the table.\n      String sql = databaseMeta.getSQLColumnExists( columnname, tablename );\n\n      try {\n        getOneRow( sql );\n        return true;\n      } catch ( KettleDatabaseException e ) {\n        return false;\n      }\n    } catch ( Exception e ) {\n      throw new KettleDatabaseException( \"Unable to check if column [\"\n        + columnname + \"] exists in table [\" + tablename + \"] on connection [\" + databaseMeta.getName() + \"]\", e );\n    }\n  }\n\n  /**\n   * Check whether the sequence exists, Oracle only!\n   *\n   * @param sequenceName The name of the sequence\n   * @return true if the sequence exists.\n   */\n  public boolean checkSequenceExists( String sequenceName ) throws KettleDatabaseException {\n    return checkSequenceExists( null, sequenceName );\n  }\n\n  /**\n   * Check whether the sequence exists, Oracle only!\n   *\n   * @param sequenceName The name of the sequence","sourceCodeStart":2344,"sourceCodeEnd":2380,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/core/src/main/java/org/pentaho/di/core/database/Database.java#L2344-L2380","documentation":"Outer guard of the column existence check: any unexpected Exception while verifying column existence (beyond the metadata/statement handling) is wrapped in this KettleDatabaseException naming the column, table, and connection. It means the check itself blew up, not that the column is missing.","triggerScenarios":"Any Exception inside checkColumnExists that is not the caught KettleDatabaseException from the statement probe — e.g. databaseMeta.getName() NPE on unnamed metadata, or connection errors during getOneRow.","commonSituations":"Using a DatabaseMeta with no name set (null getName in message construction), a closed connection during the probe SELECT, or driver-level failures on the test query.","solutions":["Set a name on the DatabaseMeta before use so the message and connection lookup succeed","Ensure the connection is open before calling column existence checks","Inspect the wrapped cause 'e' for the real failure","Validate table/column identifiers before calling to avoid driver-level parse errors"],"exampleFix":"// before\nDatabaseMeta meta = new DatabaseMeta(); // no name\n// after\nDatabaseMeta meta = new DatabaseMeta();\nmeta.setName(\"prod-db\");","handlingStrategy":"try-catch","validationCode":"if (dbMeta.getName() == null) {\n  dbMeta.setName(\"unnamed-connection\");\n}\nif (!db.checkConnectionOpen()) db.connect();","typeGuard":null,"tryCatchPattern":"try {\n  boolean ok = db.columnExists(schema, table, column);\n} catch (KettleDatabaseException e) {\n  Throwable cause = e.getCause();\n  log.error(\"column check failed on \" + dbMeta.getName() + \": \" + cause, cause);\n}","preventionTips":["Name every DatabaseMeta instance","Keep the connection open during checks","Validate identifiers (no illegal characters) before probing"],"tags":["column-exists","jdbc","unexpected-exception"],"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"}