alibaba/druid · critical · SQLException

url not set

Error message

url not set

What it means

SQLException('url not set') thrown in resolveDriver() when no Driver instance is provided AND both jdbcUrl is null and driverClass is null/empty. Without either a URL or a driver class, Druid has nothing to load a JDBC driver from, so it refuses to proceed with driver resolution.

Source

Thrown at core/src/main/java/com/alibaba/druid/pool/DruidDataSource.java:1137

            }

            if (MockDriver.class.getName().equals(driverClass)) {
                driver = MockDriver.instance;
            } else if ("com.alibaba.druid.support.clickhouse.BalancedClickhouseDriver".equals(driverClass)) {
                Properties info = new Properties();
                info.put("user", username);
                info.put("password", password);
                info.putAll(connectProperties);
                driver = new BalancedClickhouseDriver(jdbcUrl, info);
            } else if ("com.alibaba.druid.support.clickhouse.BalancedClickhouseDriverNative".equals(driverClass)) {
                Properties info = new Properties();
                info.put("user", username);
                info.put("password", password);
                info.putAll(connectProperties);
                driver = new BalancedClickhouseDriverNative(jdbcUrl, info);
            } else {
                if (jdbcUrl == null && (driverClass == null || driverClass.length() == 0)) {
                    throw new SQLException("url not set");
                }
                driver = JdbcUtils.createDriver(driverClassLoader, driverClass);
            }
        } else {
            if (this.driverClass == null) {
                this.driverClass = driver.getClass().getName();
            }
        }
    }

    protected void initCheck() throws SQLException {
        DbType dbType = DbType.of(this.dbTypeName);

        if (dbType == DbType.oracle) {
            isOracle = true;

            // Some Oracle-compatible databases may use non-Oracle JDBC drivers (e.g. YashanDB),
            // whose version numbers are not aligned with Oracle's. In that case, skip the Oracle

View on GitHub (pinned to fa8dc99126)

Solutions

  1. Call dataSource.setUrl("jdbc:...") (or setJdbcUrl) before init().
  2. Alternatively set dataSource.setDriverClassName("...") so a driver can be resolved even without a url (though a url is still needed to connect).
  3. Verify your framework's property binding actually populated the url field (log dataSource.getUrl()/getJdbcUrl() before init).
  4. For Spring Boot, confirm spring.datasource.url maps to the Druid datasource (use the druid-spring-boot-starter).

Example fix

// before
DruidDataSource ds = new DruidDataSource();
ds.init(); // url not set
// after
DruidDataSource ds = new DruidDataSource();
ds.setUrl("jdbc:mysql://localhost:3306/mydb");
ds.setUsername("user");
ds.setPassword("pass");
ds.init();
Defensive patterns

Strategy: validation

Validate before calling

if ((dataSource.getJdbcUrl() == null || dataSource.getJdbcUrl().isEmpty())
    && (dataSource.getDriverClassName() == null || dataSource.getDriverClassName().isEmpty())) {
    throw new IllegalStateException("set url (or driverClassName) before init()");
}

Prevention

When it happens

Trigger: resolveDriver() reaches the else branch (line 1135) with jdbcUrl == null and (driverClass == null or empty). The check at 1136 throws before JdbcUtils.createDriver is called.

Common situations: Constructing DruidDataSource and calling init() without setUrl/setJdbcUrl and without setDriverClassName; property binding that failed to map url onto the datasource (e.g. wrong property name in Spring config); a config source returning null.

Related errors


AI-assisted analysis of alibaba/druid@fa8dc99126 (2026-08-14). Data as JSON: /api/errors/cf46580edeeac080. Report an issue: GitHub.