alibaba/druid · error · UnsupportedOperationException

Not supported by DruidDataSource

Error message

Not supported by DruidDataSource

What it means

UnsupportedOperationException thrown by getPooledConnection(String user, String password) because DruidDataSource is a single-credential pool: all connections authenticate with the datasource's configured username/password. Per-call credentials have no meaningful implementation, so the JDBC-bridged method deliberately refuses.

Source

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

            FilterChainImpl filterChain = createChain();
            try {
                return filterChain.dataSource_connect(this, maxWaitMillis);
            } finally {
                recycleFilterChain(filterChain);
            }
        } else {
            return getConnectionDirect(maxWaitMillis);
        }
    }

    @Override
    public PooledConnection getPooledConnection() throws SQLException {
        return getConnection(maxWait);
    }

    @Override
    public PooledConnection getPooledConnection(String user, String password) throws SQLException {
        throw new UnsupportedOperationException("Not supported by DruidDataSource");
    }

    public DruidPooledConnection getConnectionDirect(long maxWaitMillis) throws SQLException {
        int notFullTimeoutRetryCnt = 0;
        for (; ; ) {
            // handle notFullTimeoutRetry
            DruidPooledConnection poolableConnection;
            try {
                poolableConnection = getConnectionInternal(maxWaitMillis);
            } catch (GetConnectionTimeoutException ex) {
                if (notFullTimeoutRetryCnt < this.notFullTimeoutRetryCount && !isFull()) {
                    notFullTimeoutRetryCnt++;
                    if (LOG.isWarnEnabled()) {
                        LOG.warn("get connection timeout retry : " + notFullTimeoutRetryCnt);
                    }
                    continue;
                }
                throw ex;

View on GitHub (pinned to fa8dc99126)

Solutions

  1. Use getConnection() / getConnection(username, password) paths Druid supports, or create a separate DruidDataSource per credential set.
  2. If you need multi-tenant pooling, maintain a map of datasource instances keyed by tenant.
  3. Avoid javax.sql.ConnectionPoolDataSource-style usage of DruidDataSource; treat it as a javax.sql.DataSource.

Example fix

// before
PooledConnection pc = druidDataSource.getPooledConnection("alice", "pw"); // throws
// after
DruidDataSource aliceDs = pools.get("alice"); // pre-built per-user pool
Connection c = aliceDs.getConnection();
Defensive patterns

Strategy: type-guard

Type guard

// DruidDataSource is a single-credential pool; never call the 2-arg pooled connection API
public static boolean supportsPerUserPooledConnection(javax.sql.DataSource ds) {
    return !(ds instanceof com.alibaba.druid.pool.DruidDataSource);
}

Prevention

When it happens

Trigger: A caller invokes dataSource.getPooledConnection(user, password) (the two-argument javax.sql.PooledConnection / ConnectionPoolDataSource method). The override at line 1367 throws unconditionally.

Common situations: Generic JDBC tooling or a connection pool bridge that calls the 2-arg getPooledConnection expecting per-user pooling; code ported from a multi-tenant pool; frameworks that introspect and invoke all DataSource methods.

Related errors


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