pentaho/pentaho-kettle · error · KettleDatabaseException
Couldn't get field info from [" + sql + "]" + Const.CR
Error message
Couldn't get field info from [" + sql + "]" + Const.CR
What it means
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.
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
Example fix
// before
RowMetaInterface rm = db.getQueryFields("SELCT * FROM t", false, null, null);
// after
RowMetaInterface rm = db.getQueryFields("SELECT * FROM t", false, null, null); Defensive patterns
Strategy: validation
Validate before calling
// sanity-check SQL before handing to getQueryFields
if (sql == null || sql.trim().isEmpty()) {
throw new IllegalArgumentException("empty SQL");
} Try / catch
try {
RowMetaInterface rm = db.getQueryFields(sql, false, null, null);
} catch (KettleDatabaseException e) {
log.error("could not prepare: " + sql + " cause: " + e.getCause(), e);
} Prevention
- 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
When it happens
Trigger: Any exception while sqlRowset/getQueryFields prepares the statement or reads its metadata — syntax errors, unknown tables/columns in the SQL, closed connections.
Common situations: Dynamically generated SQL with typos, queries referencing renamed columns, using the method on a disconnected Database, or SQL the driver cannot prepare without executing.
Understand the failure class
Background: "query failed", "%w: SQL error" — wrapped database query errors in Go libraries explained — this error's family across 3 libraries.
Related errors
- Problem encountered determining query fields:
- An error occurred executing SQL:
- Couldn't execute SQL:
- Couldn't find any rows because of an error :
- Couldn't get a result because of an error :
AI-assisted analysis of pentaho/pentaho-kettle@f3058517a1 (2026-09-13).
Data as JSON: /api/errors/6c7c9fb4ceeac6a0.
Report an issue: GitHub.
Appendix: source
Thrown at core/src/main/java/org/pentaho/di/core/database/Database.java:2841
try {
//
// See PDI-14893
// If we're in this private fallback method, it's because the databasemeta returns false for
// supportsPreparedStatementMetadataRetrieval() or because we got an exception trying to do
// it the other way. In either case, there is no reason for us to ever try getting the prepared
// statement's metadata. The right answer is to directly get the resultset metadata.
//
ResultSetMetaData metadata = r.getMetaData();
fields = getRowInfo( metadata, false, false );
} finally { // should always use a try/finally to avoid leaks
r.close();
}
} finally { // should always use a try/finally to avoid leaks
ps.close();
}
}
} catch ( Exception ex ) {
throw new KettleDatabaseException( "Couldn't get field info from [" + sql + "]" + Const.CR, ex );
}
return fields;
}
public void closeQuery( ResultSet res ) throws KettleDatabaseException {
// close everything involved in the query!
try {
if ( res != null ) {
res.close();
}
if ( selStmt != null ) {
selStmt.close();
selStmt = null;
}
if ( pstmt != null ) {
pstmt.close();
pstmt = null;View on GitHub (pinned to f3058517a1)