{"record":{"id":"5766e34b53e73cfa","repo":"SonarSource/sonarqube","slug":"bad-format-of-jdbc-url-s","errorCode":null,"errorMessage":"Bad format of JDBC URL: %s","messagePattern":"Bad format of JDBC URL: (.+?)","errorType":"validation","errorClass":"MessageException","httpStatus":null,"severity":"error","filePath":"server/sonar-main/src/main/java/org/sonar/application/config/JdbcSettings.java","lineNumber":119,"sourceCode":"    Integer embeddedDatabasePort = props.valueAsInt(JDBC_EMBEDDED_PORT.getKey());\n\n    if (embeddedDatabasePort != null) {\n      String correctUrl = buildH2JdbcUrl(embeddedDatabasePort);\n      warnIfUrlIsSet(embeddedDatabasePort, url, correctUrl);\n      props.set(JDBC_URL.getKey(), correctUrl);\n      return Provider.H2;\n    }\n\n    if (isEmpty(url)) {\n      props.set(JDBC_URL.getKey(), buildH2JdbcUrl(JDBC_EMBEDDED_PORT_DEFAULT_VALUE));\n      props.set(JDBC_EMBEDDED_PORT.getKey(), String.valueOf(JDBC_EMBEDDED_PORT_DEFAULT_VALUE));\n      return Provider.H2;\n    }\n\n    Pattern pattern = Pattern.compile(\"jdbc:(\\\\w+):.+\");\n    Matcher matcher = pattern.matcher(url);\n    if (!matcher.find()) {\n      throw new MessageException(format(\"Bad format of JDBC URL: %s\", url));\n    }\n    String key = matcher.group(1);\n    try {\n      return Provider.valueOf(StringUtils.upperCase(key));\n    } catch (IllegalArgumentException e) {\n      throw new MessageException(format(\"Unsupported JDBC driver provider: %s\", key));\n    }\n  }\n\n  private static String buildH2JdbcUrl(int embeddedDatabasePort) {\n    InetAddress ip = InetAddress.getLoopbackAddress();\n    String host;\n    if (ip instanceof Inet6Address) {\n      host = \"[\" + ip.getHostAddress() + \"]\";\n    } else {\n      host = ip.getHostAddress();\n    }\n    return format(\"jdbc:h2:tcp://%s:%d/sonar%s\", host, embeddedDatabasePort, IGNORED_KEYWORDS_OPTION);","sourceCodeStart":101,"sourceCodeEnd":137,"githubUrl":"https://github.com/SonarSource/sonarqube/blob/184c821202192afc1c599fc912d0889b69fffa53/server/sonar-main/src/main/java/org/sonar/application/config/JdbcSettings.java#L101-L137","documentation":"JdbcSettings derives the database Provider from the JDBC URL by matching the pattern jdbc:(\\w+):.+. If the URL does not match (missing sub-protocol or body), a MessageException 'Bad format of JDBC URL: <url>' is thrown. This is URL syntax validation before provider resolution.","triggerScenarios":"Passing a sonar.jdbc.url that does not look like 'jdbc:<db>:<rest>', e.g. 'postgresql://localhost/sonar' (missing jdbc: prefix) or 'jdbc:' alone.","commonSituations":"Copying a connection-string format from a non-JDBC tool; forgetting the jdbc: prefix; truncating the URL during editing of sonar.properties; using env-var substitution that resolves to an empty/garbled value.","solutions":["Start the URL with 'jdbc:' followed by the database type, e.g. jdbc:postgresql://host:5432/sonar","Ensure text follows the sub-protocol (the '.+' part of the pattern)","Escape spaces/quotes in sonar.properties so the full URL reaches the parser","Verify the property via server startup logs before restarting"],"exampleFix":"// before\nsonar.jdbc.url=postgresql://localhost:5432/sonar\n// after\nsonar.jdbc.url=jdbc:postgresql://localhost:5432/sonar","handlingStrategy":"validation","validationCode":"Pattern JDBC_URL = Pattern.compile(\"jdbc:(\\\\w+):.+\");\nif (url == null || !JDBC_URL.matcher(url).find()) throw new IllegalArgumentException(\"Not a valid JDBC URL: \" + url);","typeGuard":"static boolean isValidJdbcUrl(String url) { return url != null && Pattern.matches(\"jdbc:\\\\w+:.+\", url); }","tryCatchPattern":"try { jdbcSettings.start(); } catch (MessageException e) { if (e.getMessage().startsWith(\"Bad format of JDBC URL\")) { fixUrlConfig(); } throw e; }","preventionTips":["Always include the jdbc: prefix and a sub-protocol","Copy URLs from official driver documentation, not generic tools","Validate sonar.properties after editing (regex check the jdbc.url)","Beware env-var substitution producing empty/whitespace values"],"tags":["jdbc","url","validation","sonarqube"],"backgroundTag":"invalid-url-format","analyzedSha":"184c821202192afc1c599fc912d0889b69fffa53","analyzedAt":"2026-09-09T12:23:51.573Z","contentChangedAt":"2026-09-09T12:23:51.573Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}