{"record":{"id":"d04399b1925f0a91","repo":"testcontainers/testcontainers-java","slug":"could-create-jdbc-statement","errorCode":null,"errorMessage":"Could create JDBC statement","messagePattern":"Could create JDBC statement","errorType":"exception","errorClass":"ConnectionCreationException","httpStatus":null,"severity":"error","filePath":"modules/jdbc/src/main/java/org/testcontainers/jdbc/ContainerLessJdbcDelegate.java","lineNumber":33,"sourceCode":" * @see org.testcontainers.ext.ScriptUtils\n */\n@Slf4j\npublic class ContainerLessJdbcDelegate extends JdbcDatabaseDelegate {\n\n    private Connection connection;\n\n    public ContainerLessJdbcDelegate(Connection connection) {\n        super(null, \"\");\n        this.connection = connection;\n    }\n\n    @Override\n    protected Statement createNewConnection() {\n        try {\n            return connection.createStatement();\n        } catch (SQLException e) {\n            log.error(\"Could create JDBC statement\");\n            throw new ConnectionCreationException(\"Could create JDBC statement\", e);\n        }\n    }\n}\n","sourceCodeStart":15,"sourceCodeEnd":37,"githubUrl":"https://github.com/testcontainers/testcontainers-java/blob/8e549514e3f01c57d70546fbb8599d138f3903e5/modules/jdbc/src/main/java/org/testcontainers/jdbc/ContainerLessJdbcDelegate.java#L15-L37","documentation":"ContainerLessJdbcDelegate's createNewConnection throws ConnectionCreationException when connection.createStatement() fails. This delegate runs SQL against an existing external database without a container, so it fails when the supplied JDBC connection cannot produce a Statement.","triggerScenarios":"Using ContainerLessJdbcDelegate with a closed, invalid, or broken connection whose createStatement() raises SQLException.","commonSituations":"Connection already closed after pool eviction; connection created with a bad URL; reusing a connection across threads after it was invalidated.","solutions":["Verify the connection is open (connection.isClosed()) before using the delegate","Re-create the connection via DriverManager before delegating","Check the chained SQLException cause for the vendor error code","Ensure single-threaded or synchronized use of the underlying connection"],"exampleFix":"// before\nnew ContainerLessJdbcDelegate(closedConnection).execute(sql, ...);\n// after\nif (connection.isClosed()) connection = DriverManager.getConnection(url, user, pass);\nnew ContainerLessJdbcDelegate(connection).execute(sql, ...);","handlingStrategy":"validation","validationCode":"if (connection == null || connection.isClosed()) {\n    connection = DriverManager.getConnection(url, user, password);\n}","typeGuard":null,"tryCatchPattern":"try {\n    delegate.execute(statement, 0, null, null);\n} catch (ConnectionCreationException e) {\n    log.error(\"Statement creation failed on external DB\", e.getCause());\n    throw e;\n}","preventionTips":["Check connection.isClosed() before creating the delegate","Use a fresh connection per delegate instance","Avoid sharing connections across threads"],"tags":["jdbc","testcontainers","statement","connection"],"backgroundTag":"connection-refused","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"}