{"record":{"id":"19dc1aae20296be9","repo":"testcontainers/testcontainers-java","slug":"jdbc-url-matches-jdbc-tc-prefix-but-the-database-or-tag-name","errorCode":null,"errorMessage":"JDBC URL matches jdbc:tc: prefix but the database or tag name could not be identified","messagePattern":"JDBC URL matches jdbc:tc: prefix but the database or tag name could not be identified","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"modules/jdbc/src/main/java/org/testcontainers/jdbc/ConnectionUrl.java","lineNumber":94,"sourceCode":"    /**\n     * This method applies various REGEX Patterns to parse the URL associated with this instance.\n     * This is called from a @{@link ConnectionUrl#newInstance(String)} static factory method to create immutable instance of\n     * {@link ConnectionUrl}.\n     * To avoid mutation after class is instantiated, this method should not be publicly accessible.\n     */\n    private void parseUrl() {\n        /*\n        Extract from the JDBC connection URL:\n         * The database type (e.g. mysql, postgresql, ...)\n         * The docker tag, if provided.\n         * The URL query string, if provided\n       */\n        Matcher urlMatcher = Patterns.URL_MATCHING_PATTERN.matcher(this.getUrl());\n        if (!urlMatcher.matches()) {\n            //Try for Oracle pattern\n            urlMatcher = Patterns.ORACLE_URL_MATCHING_PATTERN.matcher(this.getUrl());\n            if (!urlMatcher.matches()) {\n                throw new IllegalArgumentException(\n                    \"JDBC URL matches jdbc:tc: prefix but the database or tag name could not be identified\"\n                );\n            }\n        }\n        databaseType = urlMatcher.group(\"databaseType\");\n\n        imageTag = Optional.ofNullable(urlMatcher.group(\"imageTag\"));\n\n        //String like hostname:port/database name, which may vary based on target database.\n        //Clients can further parse it as needed.\n        dbHostString = urlMatcher.group(\"dbHostString\");\n\n        //In case it matches to the default pattern\n        Matcher dbInstanceMatcher = Patterns.DB_INSTANCE_MATCHING_PATTERN.matcher(dbHostString);\n        if (dbInstanceMatcher.matches()) {\n            databaseHost = Optional.ofNullable(dbInstanceMatcher.group(\"databaseHost\"));\n            databasePort = Optional.ofNullable(dbInstanceMatcher.group(\"databasePort\")).map(Integer::valueOf);\n            databaseName = Optional.of(dbInstanceMatcher.group(\"databaseName\"));","sourceCodeStart":76,"sourceCodeEnd":112,"githubUrl":"https://github.com/testcontainers/testcontainers-java/blob/8e549514e3f01c57d70546fbb8599d138f3903e5/modules/jdbc/src/main/java/org/testcontainers/jdbc/ConnectionUrl.java#L76-L112","documentation":"ConnectionUrl.parseUrl() matches jdbc:tc: URLs against a pattern to extract database type, tag, and query parts. If the URL has the jdbc:tc: prefix but matches neither the standard nor the Oracle pattern, the database type cannot be identified and this IllegalArgumentException is thrown.","triggerScenarios":"Calling new ConnectionUrl(\"jdbc:tc:...\", ...) (or via the jdbc:tc: driver) with a malformed URL, e.g. missing database type (jdbc:tc://host/db), unsupported type spelling, or garbled query string.","commonSituations":"Typos in the database type segment (jdbc:tc:postgress:16://...); missing the //host part; hand-built URLs missing the image tag separator; URLs generated by string concatenation gone wrong.","solutions":["Use the canonical form jdbc:tc:databasetype:tag://host:port/database?query, e.g. jdbc:tc:postgresql:16://localhost:5432/test","Prefer container.getJdbcUrl() over hand-crafting jdbc:tc: URLs","Verify the database type is one the testcontainers JDBC support recognizes","Check for typos or extra characters (spaces, wrong separators) in the URL"],"exampleFix":"// before\nConnectionUrl.newInstance(\"jdbc:tc:postgres:16//localhost/db\");\n// after\nConnectionUrl.newInstance(\"jdbc:tc:postgresql:16://localhost:5432/db\");","handlingStrategy":"validation","validationCode":"static boolean isValidJdbcTcUrl(String url) { return url != null && url.matches(\"jdbc:tc:[a-z0-9]+(:[\\w.-]+)?(:.*)?//.+\"); }","typeGuard":null,"tryCatchPattern":"try { ConnectionUrl url = ConnectionUrl.newInstance(jdbcUrl); } catch (IllegalArgumentException e) { /* fix URL to jdbc:tc:type:tag://host/db form */ }","preventionTips":["Prefer container.getJdbcUrl() over hand-written jdbc:tc: URLs","Follow the documented pattern jdbc:tc:databasetype:tag://host:port/database","Validate generated URLs in CI with a regex test"],"tags":["jdbc","url-format","connectionurl"],"backgroundTag":"invalid-url-format","analyzedSha":"8e549514e3f01c57d70546fbb8599d138f3903e5","analyzedAt":"2026-09-12T14:56:41.227Z","contentChangedAt":"2026-09-12T14:56:41.227Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}