apache/shardingsphere · error · SQLFeatureNotSupportedException
isNullable
Error message
isNullable
What it means
java.sql.SQLFeatureNotSupportedException thrown by ShardingSphere JDBC's AbstractUnsupportedOperationParameterMetaData.isNullable(int). The ShardingSphere driver prepares statements locally (it only parses SQL to route shards), so it never reaches a real backend prepare and cannot know whether a '?' parameter accepts NULL. The concrete ShardingSphereParameterMetaData implements only getParameterCount(); every per-parameter metadata method inherits this final throwing override.
Source
Thrown at jdbc/src/main/java/org/apache/shardingsphere/driver/jdbc/unsupported/AbstractUnsupportedOperationParameterMetaData.java:33
* limitations under the License.
*/
package org.apache.shardingsphere.driver.jdbc.unsupported;
import org.apache.shardingsphere.driver.jdbc.adapter.WrapperAdapter;
import java.sql.ParameterMetaData;
import java.sql.SQLException;
import java.sql.SQLFeatureNotSupportedException;
/**
* Unsupported {@code ParameterMetaData} methods.
*/
public abstract class AbstractUnsupportedOperationParameterMetaData extends WrapperAdapter implements ParameterMetaData {
@Override
public final int isNullable(final int parameter) throws SQLException {
throw new SQLFeatureNotSupportedException("isNullable");
}
@Override
public final boolean isSigned(final int parameter) throws SQLException {
throw new SQLFeatureNotSupportedException("isSigned");
}
@Override
public final int getPrecision(final int parameter) throws SQLException {
throw new SQLFeatureNotSupportedException("getPrecision");
}
@Override
public final int getScale(final int parameter) throws SQLException {
throw new SQLFeatureNotSupportedException("getScale");
}
@OverrideView on GitHub (pinned to e952770a21)
Solutions
- Do not call ParameterMetaData.isNullable through the ShardingSphere driver; derive nullability from your own domain knowledge of the SQL or from table/column metadata of the underlying database.
- If you must have per-parameter metadata, execute the statement once and use ResultSetMetaData of the result, or unwrap the real backend PreparedStatement (e.g. via a direct non-sharded DataSource for metadata probes).
- Catch SQLFeatureNotSupportedException (before the generic SQLException catch) and fall back to ParameterMetaData.parameterNoNulls/parameterNullableUnknown semantics.
Example fix
// before
int nullable = ps.getParameterMetaData().isNullable(1);
// after
int nullable;
try {
nullable = ps.getParameterMetaData().isNullable(1);
} catch (final SQLFeatureNotSupportedException e) {
nullable = ParameterMetaData.parameterNullableUnknown; // ShardingSphere cannot know pre-execution
} Defensive patterns
Strategy: try-catch
Validate before calling
// Only getParameterCount() is safe on ShardingSphere ParameterMetaData
boolean isSS;
try { isSS = conn.getMetaData().getDriverName().toLowerCase().contains("shardingsphere"); } catch (SQLException e) { isSS = false; }
if (!isSS) { int n = pmd.isNullable(1); } else { /* skip probe */ } Type guard
static boolean isShardingSphereParameterMetaData(final ParameterMetaData pmd) {
return pmd != null && pmd.getClass().getName().startsWith("org.apache.shardingsphere.driver.jdbc");
} Try / catch
try {
int nullable = pmd.isNullable(1);
} catch (final SQLFeatureNotSupportedException e) {
nullable = ParameterMetaData.parameterNullableUnknown; // catch BEFORE generic SQLException
} Prevention
- Treat ParameterMetaData from ShardingSphere as count-only metadata
- Get nullability from DatabaseMetaData.getColumns of the underlying database
- Gate driver-specific metadata probes on conn.getMetaData().getDriverName()
When it happens
Trigger: Calling ((ShardingSpherePreparedStatement) ps).getParameterMetaData().isNullable(paramIndex) on a connection whose URL is jdbc:shardingsphere:... . Any library that probes parameter nullability before binding (report writers, generic query builders, JDBC spec-compliance suites) hits it.
Common situations: Running MyBatis/Hibernate/Jooq-free generic DAO layers, Spring's SqlParameterSource probing, or BI/report tools (JasperReports, BIRT) on top of sharding-jdbc after adding sharding or encrypt rules; also appears when porting an app from MySQL Connector/J (which supports isNullable) to ShardingSphere.
Related errors
AI-assisted analysis of apache/shardingsphere@e952770a21 (2026-08-14).
Data as JSON: /api/errors/08c28da92a5c73f0.
Report an issue: GitHub.