{"record":{"id":"2fb19f52d8a39686","repo":"testcontainers/testcontainers-java","slug":"failed-to-execute-sql-script-statement-at-line-of-resource","errorCode":null,"errorMessage":"Failed to execute SQL script statement at line {} of resource {}: {}","messagePattern":"Failed to execute SQL script statement at line (.+?) of resource (.+?): (.+?)","errorType":"exception","errorClass":"ScriptUtils.ScriptStatementFailedException","httpStatus":null,"severity":"error","filePath":"modules/jdbc/src/main/java/org/testcontainers/jdbc/JdbcDatabaseDelegate.java","lineNumber":63,"sourceCode":"        int lineNumber,\n        boolean continueOnError,\n        boolean ignoreFailedDrops\n    ) {\n        try {\n            boolean rowsAffected = getConnection().execute(statement);\n            log.debug(\"{} returned as updateCount for SQL: {}\", rowsAffected, statement);\n        } catch (SQLException ex) {\n            boolean dropStatement = statement.trim().toLowerCase().startsWith(\"drop\");\n            if (continueOnError || (dropStatement && ignoreFailedDrops)) {\n                log.debug(\n                    \"Failed to execute SQL script statement at line {} of resource {}: {}\",\n                    lineNumber,\n                    scriptPath,\n                    statement,\n                    ex\n                );\n            } else {\n                throw new ScriptUtils.ScriptStatementFailedException(statement, lineNumber, scriptPath, ex);\n            }\n        }\n    }\n\n    @Override\n    protected void closeConnectionQuietly(Statement statement) {\n        try {\n            statement.close();\n            connection.close();\n        } catch (Exception e) {\n            log.error(\"Could not close JDBC connection\", e);\n        }\n    }\n}\n","sourceCodeStart":45,"sourceCodeEnd":78,"githubUrl":"https://github.com/testcontainers/testcontainers-java/blob/8e549514e3f01c57d70546fbb8599d138f3903e5/modules/jdbc/src/main/java/org/testcontainers/jdbc/JdbcDatabaseDelegate.java#L45-L78","documentation":"When a statement in an executed SQL script fails and the target is a named resource (scriptPath non-null), JdbcDatabaseDelegate throws ScriptUtils.ScriptStatementFailedException including the line number, resource path and failed statement. It surfaces exactly which SQL line of the script failed against the database.","triggerScenarios":"Running a script via the delegate (init script path) where one statement fails — syntax error, constraint violation, or object already exists — against the container database.","commonSituations":"Idempotency issues (re-running CREATE TABLE); dialect mismatches; order-dependent statements; data violating constraints added earlier in the script.","solutions":["Read the reported line number and statement, then run it manually to see the vendor error","Fix the failing SQL at that line in the script resource","Make the script idempotent (CREATE TABLE IF NOT EXISTS, DROP ... IF EXISTS)","Check the cause exception for the vendor error code and message"],"exampleFix":"// before\nCREATE TABLE users(id INT PRIMARY KEY);\nCREATE TABLE users(id INT PRIMARY KEY); -- duplicate on re-run\n// after\nCREATE TABLE IF NOT EXISTS users(id INT PRIMARY KEY);\nCREATE TABLE IF NOT EXISTS users(id INT PRIMARY KEY);","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n    delegate.executeScript(scriptResource);\n} catch (ScriptUtils.ScriptStatementFailedException e) {\n    log.error(\"Script {} failed at line {}: {}\", e.getScript(), e.getLineNumber(), e.getStatement(), e.getCause());\n    throw e;\n}","preventionTips":["Use IF NOT EXISTS / idempotent DDL in init scripts","Validate scripts against the same engine version locally","Keep one statement per concern; avoid mixing dialects"],"tags":["jdbc","testcontainers","sql","script"],"backgroundTag":"sql-query-failed","analyzedSha":"8e549514e3f01c57d70546fbb8599d138f3903e5","analyzedAt":"2026-09-12T14:56:41.227Z","contentChangedAt":"2026-09-12T14:56:41.227Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}