{"record":{"id":"6c7c9fb4ceeac6a0","repo":"pentaho/pentaho-kettle","slug":"couldn-t-get-field-info-from-sql-const-cr","errorCode":null,"errorMessage":"Couldn't get field info from [\" + sql + \"]\" + Const.CR","messagePattern":"Couldn't get field info from \\[\" \\+ sql \\+ \"\\]\" \\+ Const\\.CR","errorType":"exception","errorClass":"KettleDatabaseException","httpStatus":null,"severity":"error","filePath":"core/src/main/java/org/pentaho/di/core/database/Database.java","lineNumber":2841,"sourceCode":"          try {\n            //\n            // See PDI-14893\n            // If we're in this private fallback method, it's because the databasemeta returns false for\n            // supportsPreparedStatementMetadataRetrieval() or because we got an exception trying to do\n            // it the other way. In either case, there is no reason for us to ever try getting the prepared\n            // statement's metadata. The right answer is to directly get the resultset metadata.\n            //\n            ResultSetMetaData metadata = r.getMetaData();\n            fields = getRowInfo( metadata, false, false );\n          } finally { // should always use a try/finally to avoid leaks\n            r.close();\n          }\n        } finally { // should always use a try/finally to avoid leaks\n          ps.close();\n        }\n      }\n    } catch ( Exception ex ) {\n      throw new KettleDatabaseException( \"Couldn't get field info from [\" + sql + \"]\" + Const.CR, ex );\n    }\n\n    return fields;\n  }\n\n  public void closeQuery( ResultSet res ) throws KettleDatabaseException {\n    // close everything involved in the query!\n    try {\n      if ( res != null ) {\n        res.close();\n      }\n      if ( selStmt != null ) {\n        selStmt.close();\n        selStmt = null;\n      }\n      if ( pstmt != null ) {\n        pstmt.close();\n        pstmt = null;","sourceCodeStart":2823,"sourceCodeEnd":2859,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/core/src/main/java/org/pentaho/di/core/database/Database.java#L2823-L2859","documentation":"getQueryFields() builds field metadata by preparing the SQL and reading its PreparedStatementMetaData; any Exception in that process is wrapped as this KettleDatabaseException including the offending SQL. It means Kettle could not determine the result fields for the given query.","triggerScenarios":"Any exception while sqlRowset/getQueryFields prepares the statement or reads its metadata — syntax errors, unknown tables/columns in the SQL, closed connections.","commonSituations":"Dynamically generated SQL with typos, queries referencing renamed columns, using the method on a disconnected Database, or SQL the driver cannot prepare without executing.","solutions":["Validate the SQL manually against the database before calling getQueryFields","Check the wrapped cause for the precise SQL error","Reconnect the Database if the session was closed","Ensure all referenced tables/columns exist with correct casing"],"exampleFix":"// before\nRowMetaInterface rm = db.getQueryFields(\"SELCT * FROM t\", false, null, null);\n// after\nRowMetaInterface rm = db.getQueryFields(\"SELECT * FROM t\", false, null, null);","handlingStrategy":"validation","validationCode":"// sanity-check SQL before handing to getQueryFields\nif (sql == null || sql.trim().isEmpty()) {\n  throw new IllegalArgumentException(\"empty SQL\");\n}","typeGuard":null,"tryCatchPattern":"try {\n  RowMetaInterface rm = db.getQueryFields(sql, false, null, null);\n} catch (KettleDatabaseException e) {\n  log.error(\"could not prepare: \" + sql + \" cause: \" + e.getCause(), e);\n}","preventionTips":["Test dynamic SQL against the DB before field lookup","Ensure referenced tables/columns exist and are correctly cased","Keep the connection open for the call"],"tags":["sql","query-fields","jdbc"],"backgroundTag":"sql-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"}