{"record":{"id":"722f955f17ebcc99","repo":"testcontainers/testcontainers-java","slug":"container-is-started-but-cannot-be-accessed-by-jdbc-url-s","errorCode":null,"errorMessage":"Container is started, but cannot be accessed by (JDBC URL: %s), please check container logs","messagePattern":"Container is started, but cannot be accessed by \\(JDBC URL: (.+?)\\), please check container logs","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"modules/jdbc/src/main/java/org/testcontainers/containers/JdbcDatabaseContainer.java","lineNumber":209,"sourceCode":"            } else {\n                try (Connection connection = createConnection(\"\"); Statement statement = connection.createStatement()) {\n                    boolean testQuerySucceeded = statement.execute(this.getTestQueryString());\n                    if (testQuerySucceeded) {\n                        return;\n                    }\n                } catch (NoDriverFoundException e) {\n                    // we explicitly want this exception to fail fast without retries\n                    throw e;\n                } catch (Exception e) {\n                    lastConnectionException = e;\n                    // ignore so that we can try again\n                    logger().debug(\"Failure when trying test query\", e);\n                    Thread.sleep(100L);\n                }\n            }\n        }\n\n        throw new IllegalStateException(\n            String.format(\n                \"Container is started, but cannot be accessed by (JDBC URL: %s), please check container logs\",\n                this.getJdbcUrl()\n            ),\n            lastConnectionException\n        );\n    }\n\n    @Override\n    protected void containerIsStarted(InspectContainerResponse containerInfo) {\n        logger().info(\"Container is started (JDBC URL: {})\", this.getJdbcUrl());\n        runInitScriptIfRequired();\n    }\n\n    /**\n     * Obtain an instance of the correct JDBC driver for this particular database container type\n     *\n     * @return a JDBC Driver","sourceCodeStart":191,"sourceCodeEnd":227,"githubUrl":"https://github.com/testcontainers/testcontainers-java/blob/8e549514e3f01c57d70546fbb8599d138f3903e5/modules/jdbc/src/main/java/org/testcontainers/containers/JdbcDatabaseContainer.java#L191-L227","documentation":"JdbcDatabaseContainer.waitUntilContainerStarted() repeatedly tries the container's test query until the startup timeout expires; if every attempt fails it throws this IllegalStateException including the JDBC URL and the last underlying connection exception as cause. It means the container process is running but the database never became reachable/ready.","triggerScenarios":"Startup timeout elapses while connect attempts keep failing during container startup wait.","commonSituations":"Database inside the container crashing at boot or taking longer than the timeout; wrong credentials so authentication fails every attempt; port mapping issues; test query incompatible with the DB image version.","solutions":["Inspect the container logs (container.getLogs()) for the database's startup error","Increase the startup timeout / use an appropriate wait strategy for the image","Verify username/password and JDBC URL parameters match the image's configuration","Check port mapping and that no other process conflicts"],"exampleFix":"// before\nnew PostgreSQLContainer(\"postgres:16\"); // default timeout, flaky startup\n// after\nPostgreSQLContainer c = new PostgreSQLContainer(\"postgres:16\");\nc.withStartupTimeout(Duration.ofMinutes(3));\nc.start();","handlingStrategy":"retry","validationCode":"// before/at startup: ensure wait strategy passes and container.isRunning() is true\nif (!container.isRunning()) throw new IllegalStateException(\"container exited early; check logs: \" + container.getLogs());","typeGuard":null,"tryCatchPattern":"try { connection = container.createConnection(\"?\"); } catch (IllegalStateException e) { System.err.println(container.getLogs()); throw e; }","preventionTips":["Use withStartupTimeout(Duration) sized for slower CI machines","Inspect container logs on any startup failure","Confirm image credentials/env config match withUsername/withPassword"],"tags":["jdbc","container-startup","timeout"],"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"}