{"record":{"id":"fc57921b40f8e417","repo":"apache/druid","slug":"cannot-create-jdbc-driver-of-class-driverclassna","errorCode":null,"errorMessage":"Cannot create JDBC driver of class '<driverClassName>' for connect URL '<url>'","messagePattern":"Cannot create JDBC driver of class '<driverClassName>' for connect URL '<url>'","errorType":"exception","errorClass":"SQLException","httpStatus":null,"severity":"critical","filePath":"server/src/main/java/org/apache/druid/metadata/BasicDataSourceExt.java","lineNumber":160,"sourceCode":"      try {\n        if (driverFromCCL == null) {\n          driverToUse = DriverManager.getDriver(getUrl());\n        } else {\n          // Usage of DriverManager is not possible, as it does not\n          // respect the ContextClassLoader\n          // N.B. This cast may cause ClassCastException which is handled below\n          driverToUse = (Driver) driverFromCCL.newInstance();\n          if (!driverToUse.acceptsURL(getUrl())) {\n            throw new SQLException(\"No suitable driver\", \"08001\");\n          }\n        }\n      }\n      catch (Exception t) {\n        String message = \"Cannot create JDBC driver of class '\" +\n                         (getDriverClassName() != null ? getDriverClassName() : \"\") +\n                         \"' for connect URL '\" + getUrl() + \"'\";\n        LOGGER.error(t, message);\n        throw new SQLException(message, t);\n      }\n    }\n\n    if (driverToUse == null) {\n      throw new RE(\"Failed to find the DB Driver\");\n    }\n\n    final Driver finalDriverToUse = driverToUse;\n\n    return () -> {\n      String user = connectorConfig.getUser();\n      if (user != null) {\n        connectionProperties.put(\"user\", user);\n      } else {\n        log(\"DBCP DataSource configured without a 'username'\");\n      }\n\n      // Note: This is the main point of this class where we are getting fresh password before setting up","sourceCodeStart":142,"sourceCodeEnd":178,"githubUrl":"https://github.com/apache/druid/blob/9b90983fd291f26935af934383ce360473179e4d/server/src/main/java/org/apache/druid/metadata/BasicDataSourceExt.java#L142-L178","documentation":"BasicDataSourceExt.createConnectionFactory catches any Exception raised while resolving the driver or probing the URL and rethrows it as SQLException('Cannot create JDBC driver of class <driverClassName> for connect URL <url>'), preserving the original cause. It is a generic wrapper for driver creation failures beyond class loading itself (e.g. the ClassCastException noted in the code, or acceptsURL throwing).","triggerScenarios":"createConnectionFactory where the driverFromCCL.newInstance() cast to Driver fails (ClassCastException — the class loaded is not a java.sql.Driver), or any other exception in the driver/URL resolution block.","commonSituations":"driverClassName pointing at a class that is not a JDBC Driver (e.g. a DataSource class or wrong class); classloader conflicts returning a different class than expected; driver initialization throwing in its constructor.","solutions":["Check the root cause in the logged stack trace and fix the specific underlying error","Set driverClassName to a class implementing java.sql.Driver (e.g. org.postgresql.Driver, com.mysql.cj.jdbc.Driver)","Remove conflicting duplicate driver jars from the classpath"],"exampleFix":"// before\ndruid.metadata.storage.connector.driverClassName=org.postgresql.ds.PGSimpleDataSource\n// after\ndruid.metadata.storage.connector.driverClassName=org.postgresql.Driver","handlingStrategy":"try-catch","validationCode":"Class<?> c = Class.forName(driverClassName); if (!java.sql.Driver.class.isAssignableFrom(c)) { throw new IllegalStateException(driverClassName + \" does not implement java.sql.Driver\"); }","typeGuard":null,"tryCatchPattern":"try { dataSource.getConnection(); } catch (SQLException e) { if (e.getMessage() != null && e.getMessage().startsWith(\"Cannot create JDBC driver of class\")) { log.error(e.getCause(), \"Driver creation failed; check cause\"); } throw e; }","preventionTips":["Point driverClassName at a java.sql.Driver implementation, not a DataSource class","Read the wrapped cause (getCause()) for the real failure","Avoid duplicate driver jars with different versions on the classpath"],"tags":["java","jdbc","driver","classcast"],"backgroundTag":"database-query-failed","analyzedSha":"9b90983fd291f26935af934383ce360473179e4d","analyzedAt":"2026-09-07T13:32:30.957Z","contentChangedAt":"2026-09-07T13:32:30.957Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}