{"record":{"id":"1693566051bbdec2","repo":"SonarSource/sonarqube","slug":"directory-does-not-contain-jdbc-driver","errorCode":null,"errorMessage":"Directory does not contain JDBC driver: ","messagePattern":"Directory does not contain JDBC driver: ","errorType":"validation","errorClass":"MessageException","httpStatus":null,"severity":"error","filePath":"server/sonar-main/src/main/java/org/sonar/application/config/JdbcSettings.java","lineNumber":88,"sourceCode":"      props.set(JDBC_ADDITIONAL_LIB_PATHS.getKey(), libPathsToBeAddedToClasspath);\n    }\n  }\n\n  private static List<String> additionalMsSqlLibPaths(File homeDir) {\n    File dir = new File(homeDir, Provider.SQLSERVER.path);\n    List<File> files = new ArrayList<>(FileUtils.listFiles(dir, new String[] {\"jar\"}, false));\n    return files.stream().filter(f -> !f.getName().startsWith(\"mssql-jdbc\")).map(File::getAbsolutePath).toList();\n  }\n\n  String driverPath(File homeDir, Provider provider) {\n    String dirPath = provider.path;\n    File dir = new File(homeDir, dirPath);\n    if (!dir.exists()) {\n      throw new MessageException(\"Directory does not exist: \" + dirPath);\n    }\n    List<File> files = new ArrayList<>(FileUtils.listFiles(dir, new String[] {\"jar\"}, false));\n    if (files.isEmpty()) {\n      throw new MessageException(\"Directory does not contain JDBC driver: \" + dirPath);\n    }\n    if (files.size() > 1 && Provider.SQLSERVER != provider) {\n      throw new MessageException(\"Directory must contain only one JAR file: \" + dirPath);\n    } else if (Provider.SQLSERVER == provider) {\n      return files.stream().filter(f -> f.getName().startsWith(\"mssql-jdbc\")).findFirst()\n        .orElseThrow(() -> new MessageException(\"Directory does not contain JDBC driver: \" + dirPath)).getAbsolutePath();\n    }\n    return files.get(0).getAbsolutePath();\n  }\n\n  Provider resolveProviderAndEnforceNonnullJdbcUrl(Props props) {\n    String url = props.value(JDBC_URL.getKey());\n    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);","sourceCodeStart":70,"sourceCodeEnd":106,"githubUrl":"https://github.com/SonarSource/sonarqube/blob/184c821202192afc1c599fc912d0889b69fffa53/server/sonar-main/src/main/java/org/sonar/application/config/JdbcSettings.java#L70-L106","documentation":"After confirming the JDBC driver directory exists, driverPath lists *.jar files in it (non-recursively). If the directory contains no JARs, a MessageException 'Directory does not contain JDBC driver: <path>' is thrown. For the SQLSERVER provider it is also thrown when no file named mssql-jdbc* is present.","triggerScenarios":"Configured driver directory exists but is empty; for Provider.SQLSERVER, the directory contains JARs but none starting with 'mssql-jdbc'.","commonSituations":"Downloading a driver but forgetting to copy it into extensions/jdbc-driver/<db>; extracting only part of a driver archive; using an older SQL Server JAR name (sqljdbc4.jar) that doesn't match the mssql-jdbc prefix.","solutions":["Place the JDBC driver JAR into the configured directory","For SQL Server, ensure the JAR filename starts with 'mssql-jdbc' (e.g. mssql-jdbc-12.4.2.jre11.jar)","Verify the JAR extension is lowercase '.jar'","Re-download the driver if the archive was extracted incompletely"],"exampleFix":"// before: empty or wrong-named jar\ncp sqljdbc4.jar $SONARQUBE_HOME/extensions/jdbc-driver/mssql/\n// after\ncp mssql-jdbc-12.4.2.jre11.jar $SONARQUBE_HOME/extensions/jdbc-driver/mssql/","handlingStrategy":"validation","validationCode":"File[] jars = dir.listFiles((d, n) -> n.toLowerCase().endsWith(\".jar\"));\nif (jars == null || jars.length == 0) throw new IllegalStateException(\"No driver JAR in \" + dir);\nif (isSqlServer && Arrays.stream(jars).noneMatch(j -> j.getName().startsWith(\"mssql-jdbc\"))) throw new IllegalStateException(\"No mssql-jdbc JAR\");","typeGuard":"static boolean hasDriverJar(File dir) { File[] f = dir.listFiles((d, n) -> n.endsWith(\".jar\")); return f != null && f.length > 0; }","tryCatchPattern":"try { jdbcSettings.start(); } catch (MessageException e) { if (e.getMessage().contains(\"does not contain JDBC driver\")) { downloadDriver(); } throw e; }","preventionTips":["Provision the driver JAR together with the driver directory","For SQL Server use official mssql-jdbc-named artifacts","Ensure the file extension is .jar (not .zip)","Verify driver installation after distribution upgrades"],"tags":["filesystem","jdbc","driver","sonarqube"],"backgroundTag":"missing-dependency","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"}