alibaba/druid · error · DruidRuntimeException

check connection info failed

Error message

check connection info failed

What it means

Wrapped as DruidRuntimeException when, during a url/username/password change on an already-initialized datasource (urlUserPasswordChanged branch), Druid opens a probe connection via getDriver().connect(connectUrl, connectProperties) and that connect() throws SQLException. The probe verifies the new credentials before committing them; failure aborts the change.

Source

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

            }

            String connectPassword = password != null ? password : this.password;
            if (connectPassword != null) {
                connectProperties.put("password", connectPassword);
            }
            connectUrl = url != null ? url : this.jdbcUrl;
        } finally {
            lock.unlock();
        }

        if (urlUserPasswordChanged) {
            Connection conn = null;
            try {
                conn = getDriver().connect(connectUrl, connectProperties);
                LOG.info("check connection info success");
                // ignore
            } catch (SQLException e) {
                throw new DruidRuntimeException("check connection info failed", e);
            } finally {
                JdbcUtils.close(conn);
            }
        }

        lock.lock();
        try {
            if (urlUserPasswordChanged) {
                if (url != null && !url.equals(this.jdbcUrl)) {
                    this.jdbcUrl = url; // direct set url, ignore init check
                    LOG.info("jdbcUrl changed");
                }

                if (username != null && !username.equals(this.username)) {
                    this.username = username; // direct set, ignore init check
                    LOG.info("username changed");
                }

View on GitHub (pinned to fa8dc99126)

Solutions

  1. Verify the new url/username/password connect manually (psql, mysql client, or a small JDBC snippet) before calling the setter.
  2. Check network reachability and DB grants for the new credentials.
  3. If you must reconfigure wholesale, prefer close()+restart(properties) over mutating an inited pool.
  4. Catch DruidRuntimeException around the setter to surface the wrapped SQLException cause for the real DB error.

Example fix

// before
dataSource.setUsername("appuser");
dataSource.setPassword("typo-password"); // probe connect fails -> wrapped exception
// after
// validate first
try (Connection c = DriverManager.getConnection(newUrl, "appuser", correctPwd)) {
    // ok
}
dataSource.setUsername("appuser");
dataSource.setPassword(correctPwd);
Defensive patterns

Strategy: try-catch

Validate before calling

// Pre-validate the new credentials before pushing them into the inited pool
try (Connection probe = DriverManager.getConnection(newUrl, newUser, newPass)) {
    // connect ok
} catch (SQLException e) {
    throw new IllegalArgumentException("new credentials invalid", e);
}

Try / catch

try {
    dataSource.setUsername(newUser);
    dataSource.setPassword(newPass);
} catch (com.alibaba.druid.support.logging.DruidRuntimeException e) {
    if (e.getMessage().contains("check connection info failed")) {
        // wrapped SQLException cause has the real DB error
        throw new IllegalStateException("credential rotation failed", e.getCause());
    }
    throw e;
}

Prevention

When it happens

Trigger: Calling setUrl/setUsername/setPassword on an inited datasource triggers the urlUserPasswordChanged block at line 254; getDriver().connect() throws SQLException at line 257, caught at 260 and rethrown wrapped at 261.

Common situations: Rotating DB credentials at runtime with wrong password; pointing an inited datasource at a new url that is unreachable; new credentials lacking connect permission; network/firewall blocking the probe connect.

Related errors


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