MyCATApache/Mycat-Server · error · ConfigException
invalid jdbc url of
Error message
invalid jdbc url ${nodeUrl} of ${dataHost} What it means
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.
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
Example fix
// before (schema.xml) <dbDriver>jdbc</dbDriver> <url>jdbc:mysql:10.0.0.1:3306/db1</url> // after <dbDriver>jdbc</dbDriver> <url>jdbc:mysql://10.0.0.1:3306/db1</url>
Defensive patterns
Strategy: validation
Validate before calling
// validate jdbc urls for dbDriver=jdbc dataHosts
if ("jdbc".equalsIgnoreCase(dbDriver)) {
try {
new URI(url.substring(5));
} catch (URISyntaxException e) {
throw new IllegalStateException("Invalid jdbc url: " + url);
}
} Type guard
boolean isValidJdbcUrl(String url) {
return url != null && url.startsWith("jdbc:")
&& url.substring(5).matches("^[a-zA-Z]+://[^\s/:]+:\d+.*");
} Try / catch
try {
schemaLoader.load();
} catch (ConfigException e) {
LOG.error("Invalid JDBC URL in schema.xml: " + e.getMessage());
throw new ConfigurationException("Correct the dataHost url attribute", e);
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
Background: "Invalid URL" errors: why new URL(), URI.parse, and reqwest::Url reject your string — missing scheme, whitespace, and bad path format — this error's family across 39 libraries.
Related errors
- Unexpected exception
- global seq and share join and special…
- CallableStatement not supported
- type not supported yet
- concurrency not supported yet
AI-assisted analysis of MyCATApache/Mycat-Server@65f8d8beb7 (2026-09-11).
Data as JSON: /api/errors/317ef677f7739539.
Report an issue: GitHub.
Appendix: source
Thrown at src/main/java/io/mycat/config/loader/xml/XMLSchemaLoader.java:731
String ip = null;
int port = 0;
if (empty(nodeHost) || empty(nodeUrl) || empty(user)) {
throw new ConfigException(
"dataHost "
+ dataHost
+ " define error,some attributes of this element is empty: "
+ nodeHost);
}
if ("native".equalsIgnoreCase(dbDriver)) {
int colonIndex = nodeUrl.indexOf(':');
ip = nodeUrl.substring(0, colonIndex).trim();
port = Integer.parseInt(nodeUrl.substring(colonIndex + 1).trim());
} else {
URI url;
try {
url = new URI(nodeUrl.substring(5));
} catch (Exception e) {
throw new ConfigException("invalid jdbc url " + nodeUrl + " of " + dataHost);
}
ip = url.getHost();
port = url.getPort();
}
DBHostConfig conf = new DBHostConfig(nodeHost, ip, port, nodeUrl, user, passwordEncryty, password,checkAlive);
conf.setDbType(dbType);
conf.setMaxCon(maxCon);
conf.setMinCon(minCon);
conf.setFilters(filters);
conf.setLogTime(logTime);
conf.setWeight(weight); //新增权重
return conf;
}
private void loadDataHosts(Element root) {
NodeList list = root.getElementsByTagName("dataHost");
for (int i = 0, n = list.getLength(); i < n; ++i) {View on GitHub (pinned to 65f8d8beb7)