alibaba/druid · error · UnsupportedOperationException
Not supported by HighAvailableDataSource.
Error message
Not supported by HighAvailableDataSource.
What it means
HighAvailableDataSource.getConnection(String username, String password) is explicitly unimplemented — it always throws UnsupportedOperationException. The HA datasource routes through a selector that picks one of several underlying DruidDataSources and only supports the no-arg getConnection(), because per-call credential routing is not part of its design. Use the no-arg form with credentials configured on the underlying data sources.
Source
Thrown at core/src/main/java/com/alibaba/druid/pool/ha/HighAvailableDataSource.java:234
public boolean isInBlackList(String name) {
return blacklist.contains(name);
}
public void setSelector(String name) {
DataSourceSelector selector = DataSourceSelectorFactory.getSelector(name, this);
if (selector != null) {
selector.init();
setDataSourceSelector(selector);
}
}
public String getSelector() {
return selector == null ? null : selector.getName();
}
@Override
public Connection getConnection(String username, String password) throws SQLException {
throw new UnsupportedOperationException("Not supported by HighAvailableDataSource.");
}
@Override
public void setLoginTimeout(int seconds) {
DriverManager.setLoginTimeout(seconds);
}
@Override
public int getLoginTimeout() {
return DriverManager.getLoginTimeout();
}
public Logger getParentLogger() throws SQLFeatureNotSupportedException {
throw new SQLFeatureNotSupportedException();
}
public void setConnectionProperties(String connectionProperties) {
this.connectionProperties = connectionProperties;View on GitHub (pinned to fa8dc99126)
Solutions
- Use the no-arg getConnection() and set username/password on each underlying DruidDataSource in the HA group.
- If per-user connections are required, do not use HighAvailableDataSource — use a routing/abstract datasource that supports credential parameters, or obtain a specific underlying DataSource explicitly.
- Configure the framework (e.g. Spring) to call getConnection() rather than getConnection(username, password).
Example fix
// before
Connection c = haDataSource.getConnection("alice", "secret"); // throws
// after
// configure credentials on each underlying source once:
// ds1.setUsername("alice"); ds1.setPassword("secret");
Connection c = haDataSource.getConnection(); Defensive patterns
Strategy: validation
Validate before calling
// Do not call the two-arg form on HA data sources:
if (ds instanceof HighAvailableDataSource) {
throw new IllegalArgumentException("use getConnection() and set credentials on the underlying sources");
} Type guard
public static boolean supportsCredentialedGetConnection(DataSource ds) {
return !(ds instanceof HighAvailableDataSource);
} Try / catch
try {
conn = ds.getConnection(user, pass);
} catch (UnsupportedOperationException e) {
if (e.getMessage().contains("HighAvailableDataSource")) {
conn = ds.getConnection(); // credentials already on underlying sources
} else throw e;
} Prevention
- Set credentials on each underlying DruidDataSource in the HA group, not per-call.
- Wire frameworks to call the no-arg getConnection().
- Use a different DataSource type if per-user credentials are truly required.
When it happens
Trigger: Calling highAvailableDataSource.getConnection(user, pass) directly, or wiring HighAvailableDataSource into a framework that invokes the two-argument getConnection (e.g. some connection providers, JdbcTemplate with explicit credentials, or user/password supplied in code).
Common situations: Migrating from a plain DruidDataSource (which accepts user/password per call) to HighAvailableDataSource without removing the per-call credentials; container-managed auth that resolves a subject and calls getConnection(user,pwd).
Related errors
- Not supported by DruidDataSource
- not support
- statement is closed
- No Observer(such as PoolUpdater) specified.
- ZK Client is NULL, Please set the zkConnectString.
AI-assisted analysis of alibaba/druid@fa8dc99126 (2026-08-14).
Data as JSON: /api/errors/38a16eb9fd5ea80b.
Report an issue: GitHub.