{"record":{"id":"4f6eff783b417d39","repo":"pentaho/pentaho-kettle","slug":"database-exception-unabletogetmetadata","errorCode":null,"errorMessage":"Database.Exception.UnableToGetMetadata","messagePattern":"Database\\.Exception\\.UnableToGetMetadata","errorType":"exception","errorClass":"KettleDatabaseException","httpStatus":null,"severity":"error","filePath":"core/src/main/java/org/pentaho/di/core/database/Database.java","lineNumber":3403,"sourceCode":"      throw new KettleDatabaseException( \"Error looking up row in database\", ex );\n    } finally {\n      log.snap( Metrics.METRIC_DATABASE_GET_LOOKUP_STOP, databaseMeta.getName() );\n    }\n  }\n\n  public DatabaseMetaData getDatabaseMetaData() throws KettleDatabaseException {\n    if ( dbmd == null ) {\n      try {\n        log.snap( Metrics.METRIC_DATABASE_GET_DBMETA_START, databaseMeta.getName() );\n\n        if ( connection == null ) {\n          throw new KettleDatabaseException( BaseMessages.getString( PKG,\n            \"Database.Exception.EmptyConnectionError\", databaseMeta.getDatabaseName() ) );\n        }\n\n        dbmd = connection.getMetaData(); // Only get the metadata once!\n      } catch ( Exception e ) {\n        throw new KettleDatabaseException( BaseMessages.getString( PKG,\n          \"Database.Exception.UnableToGetMetadata\" ), e );\n      } finally {\n        log.snap( Metrics.METRIC_DATABASE_GET_DBMETA_STOP, databaseMeta.getName() );\n      }\n    }\n    return dbmd;\n  }\n\n  public String getDDL( String tablename, RowMetaInterface fields ) throws KettleDatabaseException {\n    return getDDL( tablename, fields, null, false, null, true );\n  }\n\n  public String getDDL( String tablename, RowMetaInterface fields, String tk, boolean useAutoinc, String pk )\n    throws KettleDatabaseException {\n    return getDDL( tablename, fields, tk, useAutoinc, pk, true );\n  }\n\n  public String getDDL( String tableName, RowMetaInterface fields, String tk, boolean useAutoinc, String pk,","sourceCodeStart":3385,"sourceCodeEnd":3421,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/core/src/main/java/org/pentaho/di/core/database/Database.java#L3385-L3421","documentation":"Thrown by Database.getDatabaseMetaData() when any exception occurs while obtaining the JDBC DatabaseMetaData - either the null-connection check's own message or a failure from connection.getMetaData(). The chained exception holds the root cause.","triggerScenarios":"connection.getMetaData() throwing (driver error, closed connection raced by another thread), or the metadata retrieval path failing for any reason while dbmd is still null.","commonSituations":"Driver incompatibilities where getMetaData() is unsupported or buggy; connection closed concurrently by another thread; severe connection corruption after network failures.","solutions":["Inspect the chained exception cause for the driver's actual message","Reconnect (disconnect()/connect()) before retrying metadata retrieval","Upgrade or replace the JDBC driver if getMetaData() is known-buggy","Avoid sharing one Database object across threads"],"exampleFix":"// before\nDatabaseMetaData md = sharedDb.getDatabaseMetaData(); // shared across threads, connection closed concurrently\n// after\nsynchronized (dbLock) {\n  if ( !db.checkConnection() ) { db.disconnect(); db.connect(); }\n  DatabaseMetaData md = db.getDatabaseMetaData();\n}","handlingStrategy":"try-catch","validationCode":"if ( !database.checkConnection() ) { database.disconnect(); database.connect(); }","typeGuard":null,"tryCatchPattern":"try {\n  md = database.getDatabaseMetaData();\n} catch ( KettleDatabaseException e ) {\n  logError(\"getDatabaseMetaData failed, cause: \" + e.getCause(), e); // root driver error is chained\n  throw e;\n}","preventionTips":["Keep JDBC drivers current and compatible with the DB version","Restrict a Database instance to a single thread","Reconnect after network failures before requesting metadata","Log e.getCause(), not just the wrapper message, when diagnosing"],"tags":["jdbc","database","metadata","driver"],"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"}