{"record":{"id":"a3a57cda9d9ea852","repo":"pentaho/pentaho-kettle","slug":"error-executing-query","errorCode":null,"errorMessage":"ERROR executing query","messagePattern":"ERROR executing query","errorType":"exception","errorClass":"KettleDatabaseException","httpStatus":null,"severity":"error","filePath":"core/src/main/java/org/pentaho/di/core/database/Database.java","lineNumber":2117,"sourceCode":"\n      if ( rowlimit > 0 && databaseMeta.supportsSetMaxRows() ) {\n        ps.setMaxRows( rowlimit );\n      }\n\n      log.snap( Metrics.METRIC_DATABASE_EXECUTE_SQL_START, databaseMeta.getName() );\n      res = ps.executeQuery();\n      log.snap( Metrics.METRIC_DATABASE_EXECUTE_SQL_STOP, databaseMeta.getName() );\n\n      // MySQL Hack only. It seems too much for the cursor type of operation on\n      // MySQL, to have another cursor opened\n      // to get the length of a String field. So, on MySQL, we ignore the length\n      // of Strings in result rows.\n      //\n      log.snap( Metrics.METRIC_DATABASE_GET_ROW_META_START, databaseMeta.getName() );\n      rowMeta = getRowInfo( res.getMetaData(), databaseMeta.isMySQLVariant(), false );\n      log.snap( Metrics.METRIC_DATABASE_GET_ROW_META_STOP, databaseMeta.getName() );\n    } catch ( Exception e ) {\n      throw new KettleDatabaseException( \"ERROR executing query\", e );\n    } finally {\n      log.snap( Metrics.METRIC_DATABASE_OPEN_QUERY_STOP, databaseMeta.getName() );\n    }\n\n    return res;\n  }\n\n  void setMysqlFetchSize( PreparedStatement ps, int fs, int getMaxRows ) throws SQLException, KettleDatabaseException {\n    if ( databaseMeta.isStreamingResults() && getDatabaseMetaData().getDriverMajorVersion() == 3 ) {\n      ps.setFetchSize( Integer.MIN_VALUE );\n    } else if ( fs <= getMaxRows ) {\n      // PDI-11373 do not set fetch size more than max rows can returns\n      ps.setFetchSize( fs );\n    }\n  }\n\n  /**\n   * Returns a RowMeta describing the fields of a table expression.","sourceCodeStart":2099,"sourceCodeEnd":2135,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/core/src/main/java/org/pentaho/di/core/database/Database.java#L2099-L2135","documentation":"Thrown by Database.openQuery(...) variants that fetch row layout via getRowInfo(res.getMetaData(), ...) — the query itself succeeded, but extracting the ResultSetMetaData / building the RowMetaInterface failed. Message 'ERROR executing query' with the exception as cause.","triggerScenarios":"Database.getRows/openQuery paths that call getRowInfo(...) when the JDBC metadata access throws — e.g. driver returns null or invalid metadata, or the result set was already closed/consumed.","commonSituations":"Buggy or too-old JDBC drivers with incomplete ResultSetMetaData support; result set closed by timeout before metadata is read; exotic column types the driver cannot describe.","solutions":["Inspect the cause stack trace to see which metadata call failed","Update the JDBC driver to a version with correct ResultSetMetaData support","Avoid lazy conversion or unusual column types if the driver cannot describe them","Check that the result set is read immediately after openQuery, before any timeout closes it"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"if (database.getConnection() == null) throw new IllegalStateException(\"No connection for query metadata\");","typeGuard":null,"tryCatchPattern":"try {\n  ResultSet rs = database.openQuery(sql);\n  RowMetaInterface rm = database.getReturnRowMeta();\n} catch (KettleDatabaseException e) {\n  logError(\"Failed reading row metadata for query\", e);\n  throw e;\n}","preventionTips":["Keep JDBC drivers up to date (ResultSetMetaData bugs are the usual cause)","Read metadata immediately after opening the query","Avoid result-set timeouts closing it before metadata extraction"],"tags":["database","jdbc","metadata"],"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"}