apache/shardingsphere · error · SQLFeatureNotSupportedException
prepareCall
Error message
prepareCall
What it means
ShardingSphere's JDBC driver does not implement the java.sql.Connection method prepareCall (creating a CallableStatement for invoking database stored procedures). The abstract base class AbstractUnsupportedOperationConnection, which ShardingSphereConnection extends, overrides it as final and unconditionally throws SQLFeatureNotSupportedException. ShardingSphere routes and shards SQL statements, and stored-procedure call syntax is not part of its supported routing/parsing model, so all three prepareCall overloads are permanently unsupported. 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:44
import java.sql.Clob;
import java.sql.Connection;
import java.sql.NClob;
import java.sql.SQLException;
import java.sql.SQLFeatureNotSupportedException;
import java.sql.SQLXML;
import java.sql.Struct;
import java.util.Map;
import java.util.Properties;
import java.util.concurrent.Executor;
/**
* Unsupported {@code Connection} methods.
*/
public abstract class AbstractUnsupportedOperationConnection extends WrapperAdapter implements Connection {
@Override
public final CallableStatement prepareCall(final String sql) throws SQLException {
throw new SQLFeatureNotSupportedException("prepareCall");
}
@Override
public final CallableStatement prepareCall(final String sql, final int resultSetType, final int resultSetConcurrency) throws SQLException {
throw new SQLFeatureNotSupportedException("prepareCall");
}
@Override
public final CallableStatement prepareCall(final String sql, final int resultSetType, final int resultSetConcurrency, final int resultSetHoldability) throws SQLException {
throw new SQLFeatureNotSupportedException("prepareCall");
}
@Override
public final String nativeSQL(final String sql) throws SQLException {
throw new SQLFeatureNotSupportedException("nativeSQL");
}
@OverrideView on GitHub (pinned to e952770a21)
Solutions
- Replace the stored-procedure call with plain SQL that ShardingSphere can route (rewrite the procedure logic as normal INSERT/SELECT statements, or move the logic into the application layer).
- If the procedure must run, obtain a raw driver connection for that operation: create a separate, non-ShardingSphere DataSource pointing at the target database and call prepareCall on it.
- If you only need the underlying database's CallableStatement, unwrap it: connection.unwrap(FooConnection.class).prepareCall(sql) (works only when the connection is not heavily wrapped and the native driver supports it).
- Check the ShardingSphere version/release notes for stored-function/procedure support before upgrading, as this has been a long-standing unsupported area.
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.prepareCall(/* args */);
} catch (final SQLFeatureNotSupportedException e) {
// expected on ShardingSphere connections: fall back to supported API
log.debug("Driver does not support prepareCall, using fallback", e);
} Prevention
- Audit code and ORM config (Hibernate jpa.procedure support, MyBatis statementType="CALLABLE") for stored-procedure usage before adopting ShardingSphere.
- Keep a separate native DataSource for procedure calls.
- Check the JDBC URL before calling optional JDBC 4 methods: connections starting with jdbc:shardingsphere: never support the lob/network-timeout/client-info/callable APIs.
- Catch java.sql.SQLFeatureNotSupportedException (parent of ShardingSphere's UnsupportedSQLOperationException) around optional driver-capability calls so the application degrades gracefully.
When it happens
Trigger: Calling Connection.prepareCall(...) with any argument combination on a Connection obtained from a ShardingSphere DataSource (jdbc:shardingsphere:... URL).
Common situations: Porting an existing application that uses stored procedures (e.g. {call some_proc(?)}) to ShardingSphere; ORM frameworks (Hibernate/JPA with stored-procedure queries, MyBatis callable statements) that call prepareCall behind the scenes; connection-pool validation or monitoring tools that probe CallableStatement support.
Related errors
AI-assisted analysis of apache/shardingsphere@e952770a21 (2026-08-14).
Data as JSON: /api/errors/c53e2387d6499644.
Report an issue: GitHub.