{"record":{"id":"77e69a0a2c4cff09","repo":"pentaho/pentaho-kettle","slug":"an-error-occurred-executing-sql-database","errorCode":null,"errorMessage":"An error occurred executing SQL:","messagePattern":"An error occurred executing SQL:","errorType":"exception","errorClass":"KettleDatabaseException","httpStatus":null,"severity":"error","filePath":"core/src/main/java/org/pentaho/di/core/database/Database.java","lineNumber":2059,"sourceCode":"          selStmt.setFetchDirection( fetchMode );\n        }\n        if ( rowlimit > 0 && databaseMeta.supportsSetMaxRows() ) {\n          selStmt.setMaxRows( rowlimit );\n        }\n\n        log.snap( Metrics.METRIC_DATABASE_EXECUTE_SQL_START, databaseMeta.getName() );\n        res = selStmt.executeQuery( databaseMeta.stripCR( sql ) );\n        log.snap( Metrics.METRIC_DATABASE_EXECUTE_SQL_STOP, databaseMeta.getName() );\n      }\n\n      // MySQL Hack only. It seems too much for the cursor type of operation on MySQL, to have another cursor opened\n      // to get the length of a String field. So, on MySQL, we ignore the length of Strings in result rows.\n      //\n      rowMeta = getRowInfo( res.getMetaData(), databaseMeta.isMySQLVariant(), lazyConversion );\n    } catch ( SQLException ex ) {\n      throw new KettleDatabaseException( \"An error occurred executing SQL: \" + Const.CR + sql, ex );\n    } catch ( Exception e ) {\n      throw new KettleDatabaseException( \"An error occurred executing SQL:\" + Const.CR + sql, e );\n    } finally {\n      log.snap( Metrics.METRIC_DATABASE_OPEN_QUERY_STOP, databaseMeta.getName() );\n    }\n\n    return res;\n  }\n\n  private boolean canWeSetFetchSize( Statement statement ) throws SQLException {\n    return databaseMeta.isFetchSizeSupported()\n      && ( statement.getMaxRows() > 0\n      || databaseMeta.getDatabaseInterface() instanceof PostgreSQLDatabaseMeta\n      || ( databaseMeta.isMySQLVariant() && databaseMeta.isStreamingResults() ) );\n  }\n\n  public ResultSet openQuery( PreparedStatement ps, RowMetaInterface params, Object[] data )\n    throws KettleDatabaseException {\n    ResultSet res;\n","sourceCodeStart":2041,"sourceCodeEnd":2077,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/core/src/main/java/org/pentaho/di/core/database/Database.java#L2041-L2077","documentation":"The non-SQLException twin of the previous error in Database.openQuery(...): any Exception other than SQLException while opening the query throws this message (note the missing space before the SQL in this variant). It signals an unexpected internal/driver failure rather than a rejected statement.","triggerScenarios":"Database.openQuery(sql) when a RuntimeException or other non-SQL exception occurs — e.g. null connection, driver class cast errors, memory issues building row metadata.","commonSituations":"Calling openQuery without an open connection; incompatible JDBC driver versions throwing unexpected runtime exceptions; Kettle lazy-conversion bugs.","solutions":["Inspect the cause stack trace for the real exception","Ensure the database connection is open before calling openQuery","Update the JDBC driver and Pentaho/Kettle version to compatible levels"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"if (!database.isOpened()) throw new IllegalStateException(\"Connection not open for openQuery\");","typeGuard":null,"tryCatchPattern":"try {\n  ResultSet rs = database.openQuery(sql);\n} catch (KettleDatabaseException e) {\n  logError(\"openQuery unexpected failure on [\" + sql + \"]\", e); // message omits space; log SQL yourself\n  throw e;\n}","preventionTips":["Open the connection before openQuery","Use supported JDBC driver versions","Log SQL explicitly; this message variant does not separate it cleanly","Avoid exotic result-set features the driver may not support"],"tags":["database","jdbc","runtime-error"],"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"}