{"record":{"id":"74553457189b3b50","repo":"pentaho/pentaho-kettle","slug":"unexpected-error-executing-sql","errorCode":null,"errorMessage":"Unexpected error executing SQL: ","messagePattern":"Unexpected error executing SQL: ","errorType":"exception","errorClass":"KettleDatabaseException","httpStatus":null,"severity":"error","filePath":"core/src/main/java/org/pentaho/di/core/database/Database.java","lineNumber":1858,"sourceCode":"          if ( upperSql.startsWith( \"INSERT\" ) ) {\n            result.setNrLinesOutput( count );\n          } else if ( upperSql.startsWith( \"UPDATE\" ) ) {\n            result.setNrLinesUpdated( count );\n          } else if ( upperSql.startsWith( \"DELETE\" ) ) {\n            result.setNrLinesDeleted( count );\n          }\n        }\n      }\n\n      // See if a cache needs to be cleared...\n      if ( upperSql.startsWith( \"ALTER TABLE\" )\n        || upperSql.startsWith( \"DROP TABLE\" ) || upperSql.startsWith( \"CREATE TABLE\" ) ) {\n        DBCache.getInstance().clear( databaseMeta.getName() );\n      }\n    } catch ( SQLException ex ) {\n      throw new KettleDatabaseException( \"Couldn't execute SQL: \" + sql + Const.CR, ex );\n    } catch ( Exception e ) {\n      throw new KettleDatabaseException( \"Unexpected error executing SQL: \" + Const.CR, e );\n    }\n\n    return result;\n  }\n\n  /**\n   * Execute a series of SQL statements, separated by ;\n   * <p/>\n   * We are already connected...\n   * <p/>\n   * Multiple statements have to be split into parts We use the \";\" to separate statements...\n   * <p/>\n   * We keep the results in Result object from Jobs\n   *\n   * @param script The SQL script to be execute\n   * @return A result with counts of the number or records updates, inserted, deleted or read.\n   * @throws KettleDatabaseException In case an error occurs\n   */","sourceCodeStart":1840,"sourceCodeEnd":1876,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/core/src/main/java/org/pentaho/di/core/database/Database.java#L1840-L1876","documentation":"Also thrown by Database.execStatement(...), but for the generic catch (Exception e) branch: any non-SQLException failure while executing the statement (e.g. NullPointerException, driver class issues, Kettle-internal errors). Note the message intentionally does not include the SQL text.","triggerScenarios":"Database.execStatement(sql) when a RuntimeException or other checked exception (not SQLException) is thrown inside the method — e.g. null databaseMeta/connection, driver misbehaving, DBCache errors.","commonSituations":"Executing SQL before opening the connection; wrong/incomplete JDBC driver version causing unexpected runtime errors; programming bugs in custom DatabaseMeta variants.","solutions":["Inspect the full stack trace of the cause to find the real runtime failure","Ensure connection.open() was called and succeeded before execStatement()","Upgrade/align the JDBC driver version with the database server","Log the SQL separately since this message does not include it"],"exampleFix":"// before\ndatabase.execStatement(sql); // connection not opened\n// after\ndatabase.connect();\ndatabase.execStatement(sql);","handlingStrategy":"try-catch","validationCode":"if (!database.isOpened()) throw new IllegalStateException(\"Open the connection before execStatement\");","typeGuard":null,"tryCatchPattern":"try {\n  database.execStatement(sql);\n} catch (KettleDatabaseException e) {\n  // message lacks SQL text — log it yourself\n  logError(\"Unexpected error executing [\" + sql + \"]\", e);\n  throw e;\n}","preventionTips":["Always connect before executing statements","Log the SQL text alongside the exception since the message omits it","Keep JDBC driver versions aligned with the server","Review custom DatabaseMeta variants for runtime bugs"],"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"}