alibaba/druid · critical · SQLException
connect error, url {}, driverClass {}
Error message
connect error, url {}, driverClass {} What it means
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.
Source
Thrown at core/src/main/java/com/alibaba/druid/pool/DruidAbstractDataSource.java:1815
long connectStartNanos = System.nanoTime();
long connectedNanos, initedNanos, validatedNanos;
Map<String, Object> variables = initVariants
? new HashMap<String, Object>()
: null;
Map<String, Object> globalVariables = initGlobalVariants
? new HashMap<String, Object>()
: null;
createStartNanosUpdater.set(this, connectStartNanos);
creatingCountUpdater.incrementAndGet(this);
try {
conn = createPhysicalConnection(url, physicalConnectProperties);
connectedNanos = System.nanoTime();
if (conn == null) {
throw new SQLException("connect error, url " + url + ", driverClass " + this.driverClass);
}
initPhysicalConnection(conn, variables, globalVariables);
initedNanos = System.nanoTime();
boolean skipSocketTimeout = "odps".equals(dbTypeName);
if (socketTimeout > 0 && !netTimeoutError && !skipSocketTimeout) {
try {
// As SQLServer-jdbc-driver 6.1.7 can use this, see https://github.com/microsoft/mssql-jdbc/wiki/SocketTimeout
conn.setNetworkTimeout(netTimeoutExecutor, socketTimeout); // here is milliseconds defined by JDBC
} catch (SQLFeatureNotSupportedException | AbstractMethodError e) {
netTimeoutError = true;
} catch (Exception ignored) {
// ignored
}
}
// call initSqls after completing socketTimeout setting.View on GitHub (pinned to fa8dc99126)
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.
Example fix
// before
dataSource.setUrl("jdbc:mysqql://localhost:3306/db");
dataSource.setDriverClassName("com.mysql.cj.jdbc.Driver");
// after
dataSource.setUrl("jdbc:mysql://localhost:3306/db");
dataSource.setDriverClassName("com.mysql.cj.jdbc.Driver"); Defensive patterns
Strategy: validation
Validate before calling
// Verify the driver accepts the url before init
java.sql.Driver d = dataSource.getDriver() != null ? dataSource.getDriver()
: java.sql.DriverManager.getDriver(dataSource.getUrl());
if (!d.acceptsURL(dataSource.getUrl())) {
throw new IllegalStateException("driver " + d.getClass().getName() + " does not accept url " + dataSource.getUrl());
} Try / catch
try {
dataSource.init();
} catch (SQLException e) {
if (e.getMessage() != null && e.getMessage().startsWith("connect error, url")) {
// url/driver mismatch or missing driver jar
throw new IllegalStateException("Driver/URL mismatch or missing driver JAR", e);
}
throw e;
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- check connection info failed
- url not set
- driverClassName length > 256.
- validationQuery didn't return a row
- dataSource inited.
AI-assisted analysis of alibaba/druid@fa8dc99126 (2026-08-14).
Data as JSON: /api/errors/b9650651babf800b.
Report an issue: GitHub.