{"record":{"id":"be7c907279859f83","repo":"testcontainers/testcontainers-java","slug":"failed-to-execute-database-script-from-resource-script","errorCode":null,"errorMessage":"Failed to execute database script from resource [\" + script + \"]","messagePattern":"Failed to execute database script from resource \\[\" \\+ script \\+ \"\\]","errorType":"exception","errorClass":"org.testcontainers.ext.UncategorizedScriptException","httpStatus":null,"severity":"error","filePath":"modules/database-commons/src/main/java/org/testcontainers/ext/ScriptUtils.java","lineNumber":319,"sourceCode":"                blockCommentStartDelimiter,\n                blockCommentEndDelimiter,\n                statements\n            );\n\n            try (DatabaseDelegate closeableDelegate = databaseDelegate) {\n                closeableDelegate.execute(statements, scriptPath, continueOnError, ignoreFailedDrops);\n            }\n\n            long elapsedTime = TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - startTime);\n            if (LOGGER.isInfoEnabled()) {\n                LOGGER.info(\"Executed database script from \" + scriptPath + \" in \" + elapsedTime + \" ms.\");\n            }\n        } catch (Exception ex) {\n            if (ex instanceof ScriptException) {\n                throw (ScriptException) ex;\n            }\n\n            throw new UncategorizedScriptException(\n                \"Failed to execute database script from resource [\" + script + \"]\",\n                ex\n            );\n        }\n    }\n\n    public static class ScriptLoadException extends RuntimeException {\n\n        public ScriptLoadException(String message) {\n            super(message);\n        }\n\n        public ScriptLoadException(String message, Throwable cause) {\n            super(message, cause);\n        }\n    }\n\n    public static class ScriptParseException extends RuntimeException {","sourceCodeStart":301,"sourceCodeEnd":337,"githubUrl":"https://github.com/testcontainers/testcontainers-java/blob/8e549514e3f01c57d70546fbb8599d138f3903e5/modules/database-commons/src/main/java/org/testcontainers/ext/ScriptUtils.java#L301-L337","documentation":"ScriptUtils.executeDatabaseScript catches any non-ScriptException thrown while executing a database script and wraps it in UncategorizedScriptException with this message naming the script resource. It's the general-purpose wrapper for unexpected failures (connection errors, runtime exceptions from the delegate) during script execution.","triggerScenarios":"Any exception other than ScriptException escaping the statement execution loop: DatabaseDelegate connection failures, RuntimeExceptions from JDBC, null/blank statements handling bugs.","commonSituations":"Database not yet ready when the script runs; wrong credentials for the delegate; a driver throwing a runtime exception mid-script.","solutions":["Look at the cause inside UncategorizedScriptException for the root failure.","Ensure the database container is started and its wait strategy satisfied before executing scripts.","Verify the DatabaseDelegate/connection settings (url, username, password).","If the failure is a genuine script error, expect a plain ScriptException instead; refactor so script errors aren't masked."],"exampleFix":"// before\nScriptUtils.executeDatabaseScript(delegate, \"init.sql\", script); // db not ready\n// after\nAwaitility.await().until(container::isRunning);\nScriptUtils.executeDatabaseScript(delegate, \"init.sql\", script);","handlingStrategy":"try-catch","validationCode":"if (!container.isRunning()) {\n    throw new IllegalStateException(\"Database container must be running before executing scripts\");\n}","typeGuard":null,"tryCatchPattern":"try {\n    ScriptUtils.executeDatabaseScript(delegate, scriptPath, script);\n} catch (UncategorizedScriptException e) {\n    if (e.getMessage().startsWith(\"Failed to execute database script from resource\")) {\n        Throwable root = e.getCause(); // connection/runtime failure details\n    }\n    throw e;\n}","preventionTips":["Ensure container wait strategies pass before running scripts.","Validate delegate connection settings before script execution.","Log full cause chains; this exception only wraps the real error."],"tags":["sql","script-execution","wrapper-exception","database"],"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"}