apache/shardingsphere · error · SQLFeatureNotSupportedException

getNetworkTimeout

Error message

getNetworkTimeout

What it means

ShardingSphere's JDBC driver does not implement the java.sql.Connection method getNetworkTimeout (reading the JDBC 4 network/socket timeout (milliseconds) configured on the connection). The abstract base class AbstractUnsupportedOperationConnection, which ShardingSphereConnection extends, overrides it as final and unconditionally throws SQLFeatureNotSupportedException. ShardingSphere does not expose a single network timeout across its multiple backend connections, so the getter always throws. The exception is thrown the moment the method is invoked on any connection produced by the ShardingSphere Driver.

Source

Thrown at jdbc/src/main/java/org/apache/shardingsphere/driver/jdbc/unsupported/AbstractUnsupportedOperationConnection.java:79

    
    @Override
    public final void abort(final Executor executor) throws SQLException {
        throw new SQLFeatureNotSupportedException("abort");
    }
    
    @Override
    public final Map<String, Class<?>> getTypeMap() throws SQLException {
        throw new SQLFeatureNotSupportedException("getTypeMap");
    }
    
    @Override
    public final void setTypeMap(final Map<String, Class<?>> map) throws SQLException {
        throw new SQLFeatureNotSupportedException("setTypeMap");
    }
    
    @Override
    public int getNetworkTimeout() throws SQLException {
        throw new SQLFeatureNotSupportedException("getNetworkTimeout");
    }
    
    @Override
    public void setNetworkTimeout(final Executor executor, final int milliseconds) throws SQLException {
        throw new SQLFeatureNotSupportedException("setNetworkTimeout");
    }
    
    @Override
    public Array createArrayOf(final String typeName, final Object[] elements) throws SQLException {
        throw new SQLFeatureNotSupportedException("createArrayOf");
    }
    
    @Override
    public final Blob createBlob() throws SQLException {
        throw new SQLFeatureNotSupportedException("createBlob");
    }
    
    @Override

View on GitHub (pinned to e952770a21)

Solutions

  1. Set timeouts where they are honored: pass socketTimeout/connectTimeout properties in each backend JDBC URL inside the ShardingSphere datasource configuration.
  2. Use Statement.setQueryTimeout() (supported by ShardingSphere) instead of network timeouts for query deadlines.
  3. If a framework requires getNetworkTimeout(), catch SQLFeatureNotSupportedException and fall back to a configured default value.
Defensive patterns

Strategy: try-catch

Validate before calling

boolean supportsOp = false;
try {
    connection.getMetaData(); // connection is alive
    // JDBC has no capability flag for individual methods; probe once per JVM:
    supportsOp = probeSupport(connection); // reflective/one-time guarded call
} catch (final SQLException ignored) {
}
// Simpler and recommended: capability-check by driver URL
boolean isShardingSphere = url.startsWith("jdbc:shardingsphere:");
if (isShardingSphere) {
    // skip the unsupported call, use the alternative API path
}

Try / catch

try {
    connection.getNetworkTimeout(/* args */);
} catch (final SQLFeatureNotSupportedException e) {
    // expected on ShardingSphere connections: fall back to supported API
    log.debug("Driver does not support getNetworkTimeout, using fallback", e);
}

Prevention

When it happens

Trigger: Calling Connection.getNetworkTimeout() on a ShardingSphere connection.

Common situations: Connection pools and frameworks that read network timeouts to enforce query deadlines; HikariCP-style initialization paths that inspect JDBC 4 capabilities; monitoring tools probing driver feature levels.

Understand the failure class

Related errors


AI-assisted analysis of apache/shardingsphere@e952770a21 (2026-08-14). Data as JSON: /api/errors/8e0dd73f83a73e9a. Report an issue: GitHub.