{"record":{"id":"8048393694ece240","repo":"pentaho/pentaho-kettle","slug":"couldn-t-execute-sql","errorCode":null,"errorMessage":"Couldn't execute SQL: ","messagePattern":"Couldn't execute SQL: ","errorType":"exception","errorClass":"KettleDatabaseException","httpStatus":null,"severity":"error","filePath":"core/src/main/java/org/pentaho/di/core/database/Database.java","lineNumber":1856,"sourceCode":"        // You should have called something else!\n        if ( count > 0 ) {\n          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.","sourceCodeStart":1838,"sourceCodeEnd":1874,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/core/src/main/java/org/pentaho/di/core/database/Database.java#L1838-L1874","documentation":"Thrown by Database.execStatement(...) when the JDBC Statement.executeUpdate/execute call raises a SQLException while running arbitrary SQL (DDL or DML). The original SQL text is appended to the message and the SQLException is the cause. It is the standard 'your SQL statement failed on the server' error of the Kettle Database API.","triggerScenarios":"Database.execStatement(sql) when the driver returns a SQLException — syntax error, missing table/column, insufficient privileges, or any other server-side rejection of the statement.","commonSituations":"Generated DDL in transformations failing because the target table already exists or the user lacks CREATE rights; dialect-specific SQL that is invalid on the connected database; typos in SQL script steps; schema not set so the table is not found.","solutions":["Read the wrapped SQLException (getCause()) for the exact server error and fix the SQL accordingly","Verify the table/schema and column names the SQL references actually exist for the connected user","Check the database user's privileges for the statement type (CREATE/ALTER/DROP/INSERT)","Test the exact SQL manually against the target database with the same credentials"],"exampleFix":"// before\ndatabase.execStatement(\"INSERT INTO values VALUES(1)\");\n// after\n// 'VALUES' is a reserved word on some databases\ndatabase.execStatement(\"INSERT INTO \\\"values\\\" (id) VALUES (1)\");","handlingStrategy":"try-catch","validationCode":"if (sql == null || sql.trim().isEmpty()) throw new IllegalArgumentException(\"SQL statement is empty\");","typeGuard":null,"tryCatchPattern":"try {\n  database.execStatement(sql);\n} catch (KettleDatabaseException e) {\n  Throwable cause = e.getCause();\n  if (cause instanceof SQLException) {\n    throw new SQLException(\"execStatement failed for [\" + sql + \"]: \" + cause.getMessage(), cause);\n  }\n  throw e;\n}","preventionTips":["Test generated SQL manually against the target database/dialect","Verify referenced tables, columns and user privileges before executing DDL/DML","Use DatabaseMeta-provided quote helpers for reserved-word identifiers","Check DBCache-clearing DDL (ALTER/DROP/CREATE TABLE) is valid on the target dialect"],"tags":["database","jdbc","sql","ddl"],"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"}