{"record":{"id":"b9650651babf800b","repo":"alibaba/druid","slug":"connect-error-url-driverclass","errorCode":null,"errorMessage":"connect error, url {}, driverClass {}","messagePattern":"connect error, url (.+?), driverClass (.+?)","errorType":"exception","errorClass":"SQLException","httpStatus":null,"severity":"critical","filePath":"core/src/main/java/com/alibaba/druid/pool/DruidAbstractDataSource.java","lineNumber":1815,"sourceCode":"\n        long connectStartNanos = System.nanoTime();\n        long connectedNanos, initedNanos, validatedNanos;\n\n        Map<String, Object> variables = initVariants\n                ? new HashMap<String, Object>()\n                : null;\n        Map<String, Object> globalVariables = initGlobalVariants\n                ? new HashMap<String, Object>()\n                : null;\n\n        createStartNanosUpdater.set(this, connectStartNanos);\n        creatingCountUpdater.incrementAndGet(this);\n        try {\n            conn = createPhysicalConnection(url, physicalConnectProperties);\n            connectedNanos = System.nanoTime();\n\n            if (conn == null) {\n                throw new SQLException(\"connect error, url \" + url + \", driverClass \" + this.driverClass);\n            }\n\n            initPhysicalConnection(conn, variables, globalVariables);\n            initedNanos = System.nanoTime();\n\n            boolean skipSocketTimeout = \"odps\".equals(dbTypeName);\n            if (socketTimeout > 0 && !netTimeoutError && !skipSocketTimeout) {\n                try {\n                    // As SQLServer-jdbc-driver 6.1.7 can use this, see https://github.com/microsoft/mssql-jdbc/wiki/SocketTimeout\n                    conn.setNetworkTimeout(netTimeoutExecutor, socketTimeout); // here is milliseconds defined by JDBC\n                } catch (SQLFeatureNotSupportedException | AbstractMethodError e) {\n                    netTimeoutError = true;\n                } catch (Exception ignored) {\n                    // ignored\n                }\n            }\n\n            // call initSqls after completing socketTimeout setting.","sourceCodeStart":1797,"sourceCodeEnd":1833,"githubUrl":"https://github.com/alibaba/druid/blob/fa8dc9912637a2f729eef9f55356621fec18d40e/core/src/main/java/com/alibaba/druid/pool/DruidAbstractDataSource.java#L1797-L1833","documentation":"Thrown by createPhysicalConnection when DriverManager/Driver.connect returns null instead of a Connection object. Per the JDBC contract, Driver.connect returns null when the driver does not understand the given URL (it does NOT throw). Druid treats a null connection as a hard failure and reports the URL and driverClass to help diagnose the mismatch.","triggerScenarios":"createPhysicalConnection(url, physicalConnectProperties) returns null at line 1811, hitting the conn==null check at 1814. This occurs when no registered Driver accepts the jdbcUrl prefix, or when driverClass points at a driver that does not handle the supplied url scheme.","commonSituations":"jdbcUrl typo or wrong scheme (e.g. 'jdbc:mysqql://...'); driverClass set to a driver whose acceptsURL returns false for the url; the JDBC driver JAR missing from the classpath so DriverManager hands back null; mixing url and driverClass from different databases.","solutions":["Inspect the printed url and driverClass in the message: confirm the url scheme matches the driver (e.g. 'jdbc:mysql://' with com.mysql.cj.jdbc.Driver).","Ensure the correct JDBC driver JAR is on the classpath at runtime.","If specifying driverClass explicitly, make sure it is the class whose acceptsURL(jdbcUrl) returns true.","Let Druid auto-resolve the driver by setting only jdbcUrl and leaving driverClass null, or vice-versa consistently."],"exampleFix":"// before\ndataSource.setUrl(\"jdbc:mysqql://localhost:3306/db\");\ndataSource.setDriverClassName(\"com.mysql.cj.jdbc.Driver\");\n// after\ndataSource.setUrl(\"jdbc:mysql://localhost:3306/db\");\ndataSource.setDriverClassName(\"com.mysql.cj.jdbc.Driver\");","handlingStrategy":"validation","validationCode":"// Verify the driver accepts the url before init\njava.sql.Driver d = dataSource.getDriver() != null ? dataSource.getDriver()\n    : java.sql.DriverManager.getDriver(dataSource.getUrl());\nif (!d.acceptsURL(dataSource.getUrl())) {\n    throw new IllegalStateException(\"driver \" + d.getClass().getName() + \" does not accept url \" + dataSource.getUrl());\n}","typeGuard":null,"tryCatchPattern":"try {\n    dataSource.init();\n} catch (SQLException e) {\n    if (e.getMessage() != null && e.getMessage().startsWith(\"connect error, url\")) {\n        // url/driver mismatch or missing driver jar\n        throw new IllegalStateException(\"Driver/URL mismatch or missing driver JAR\", e);\n    }\n    throw e;\n}","preventionTips":["Keep the JDBC driver JAR matching your jdbcUrl scheme on the classpath.","Let Druid auto-resolve the driver from the url instead of setting both driverClass and url inconsistently.","Smoke-test the url with a plain DriverManager.getConnection in isolation."],"tags":["connection","driver","config","classloader"],"backgroundTag":null,"analyzedSha":"fa8dc9912637a2f729eef9f55356621fec18d40e","analyzedAt":"2026-08-14T04:55:06.789Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}