{"record":{"id":"317ef677f7739539","repo":"MyCATApache/Mycat-Server","slug":"invalid-jdbc-url-nodeurl-of-datahost","errorCode":null,"errorMessage":"invalid jdbc url ${nodeUrl} of ${dataHost}","messagePattern":"invalid jdbc url (.+?) of (.+?)","errorType":"exception","errorClass":"ConfigException","httpStatus":null,"severity":"error","filePath":"src/main/java/io/mycat/config/loader/xml/XMLSchemaLoader.java","lineNumber":731,"sourceCode":"        String ip = null;\n        int port = 0;\n        if (empty(nodeHost) || empty(nodeUrl) || empty(user)) {\n            throw new ConfigException(\n                    \"dataHost \"\n                            + dataHost\n                            + \" define error,some attributes of this element is empty: \"\n                            + nodeHost);\n        }\n        if (\"native\".equalsIgnoreCase(dbDriver)) {\n            int colonIndex = nodeUrl.indexOf(':');\n            ip = nodeUrl.substring(0, colonIndex).trim();\n            port = Integer.parseInt(nodeUrl.substring(colonIndex + 1).trim());\n        } else {\n            URI url;\n            try {\n                url = new URI(nodeUrl.substring(5));\n            } catch (Exception e) {\n                throw new ConfigException(\"invalid jdbc url \" + nodeUrl + \" of \" + dataHost);\n            }\n            ip = url.getHost();\n            port = url.getPort();\n        }\n\n        DBHostConfig conf = new DBHostConfig(nodeHost, ip, port, nodeUrl, user, passwordEncryty, password,checkAlive);\n        conf.setDbType(dbType);\n        conf.setMaxCon(maxCon);\n        conf.setMinCon(minCon);\n        conf.setFilters(filters);\n        conf.setLogTime(logTime);\n        conf.setWeight(weight);    //新增权重\n        return conf;\n    }\n\n    private void loadDataHosts(Element root) {\n        NodeList list = root.getElementsByTagName(\"dataHost\");\n        for (int i = 0, n = list.getLength(); i < n; ++i) {","sourceCodeStart":713,"sourceCodeEnd":749,"githubUrl":"https://github.com/MyCATApache/Mycat-Server/blob/65f8d8beb752f935752f2a0eec0ab017facab9ef/src/main/java/io/mycat/config/loader/xml/XMLSchemaLoader.java#L713-L749","documentation":"When the dataHost's dbDriver is 'jdbc', MyCat parses nodeUrl (which starts with 'jdbc:') as a java.net.URI after stripping the first 5 characters ('jdbc:'). If that substring is not a valid URI, the loader throws this ConfigException and startup fails. The URL must contain a parseable scheme/host so MyCat can extract ip and port for the DBHostConfig.","triggerScenarios":"schema.xml <dataHost dbDriver=\"jdbc\"> with a writeHost/readHost url attribute whose value after 'jdbc:' cannot be parsed by new URI(...) — e.g. missing host, illegal characters, or a malformed jdbc:mysql:// string.","commonSituations":"Typo in the JDBC url like 'jdbc:mysql:10.0.0.1:3306' (missing //); unescaped special characters (spaces, |) in the url; url left as a template placeholder; mixing native-driver url formats with dbDriver=jdbc.","solutions":["Check the url attribute of the dataHost named in the message; make it a well-formed JDBC URL such as jdbc:mysql://host:3306/dbname","Ensure dbDriver matches the url format: use dbDriver=\"native\" with host:port style urls, or dbDriver=\"jdbc\" with a full jdbc: URL","Escape or remove illegal URI characters (spaces, non-ASCII, unescaped pipes) from the url","Add a startup-time or CI validation that constructs new URI(url.substring(5)) for every jdbc dataHost"],"exampleFix":"// before (schema.xml)\n<dbDriver>jdbc</dbDriver>\n<url>jdbc:mysql:10.0.0.1:3306/db1</url>\n// after\n<dbDriver>jdbc</dbDriver>\n<url>jdbc:mysql://10.0.0.1:3306/db1</url>","handlingStrategy":"validation","validationCode":"// validate jdbc urls for dbDriver=jdbc dataHosts\nif (\"jdbc\".equalsIgnoreCase(dbDriver)) {\n    try {\n        new URI(url.substring(5));\n    } catch (URISyntaxException e) {\n        throw new IllegalStateException(\"Invalid jdbc url: \" + url);\n    }\n}","typeGuard":"boolean isValidJdbcUrl(String url) {\n    return url != null && url.startsWith(\"jdbc:\")\n        && url.substring(5).matches(\"^[a-zA-Z]+://[^\\s/:]+:\\d+.*\");\n}","tryCatchPattern":"try {\n    schemaLoader.load();\n} catch (ConfigException e) {\n    LOG.error(\"Invalid JDBC URL in schema.xml: \" + e.getMessage());\n    throw new ConfigurationException(\"Correct the dataHost url attribute\", e);\n}","preventionTips":["Use dbDriver=native with host:port urls and jdbc only with full jdbc:// URLs","Test-parse every JDBC URL in a CI config check","Avoid special characters needing URI escaping in url attributes"],"tags":["configuration","jdbc","url"],"backgroundTag":"invalid-url-format","analyzedSha":"65f8d8beb752f935752f2a0eec0ab017facab9ef","analyzedAt":"2026-09-11T00:12:21.696Z","contentChangedAt":"2026-09-11T00:12:21.696Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}