{"record":{"id":"87254a1bf0ad05ac","repo":"apache/shardingsphere","slug":"can-not-get-value-from-parameter-sets","errorCode":null,"errorMessage":"Can not get value from parameter sets.","messagePattern":"Can not get value from parameter sets\\.","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"jdbc/src/main/java/org/apache/shardingsphere/driver/executor/engine/batch/preparedstatement/BatchPreparedStatementExecutor.java","lineNumber":243,"sourceCode":"        return Collections.emptyList();\n    }\n    \n    private Optional<JDBCExecutionUnit> findJDBCExecutionUnit(final Statement statement, final ExecutionGroup<JDBCExecutionUnit> executionGroup) {\n        for (JDBCExecutionUnit each : executionGroup.getInputs()) {\n            if (each.getStorageResource().equals(statement)) {\n                return Optional.of(each);\n            }\n        }\n        return Optional.empty();\n    }\n    \n    private List<List<Object>> getParameterSets(final JDBCExecutionUnit executionUnit) {\n        for (BatchExecutionUnit each : batchExecutionUnits) {\n            if (isSameDataSourceAndSQL(each, executionUnit)) {\n                return each.getParameterSets();\n            }\n        }\n        throw new IllegalStateException(\"Can not get value from parameter sets.\");\n    }\n    \n    /**\n     * Clear.\n     */\n    public void clear() {\n        executionGroupContext.getInputGroups().clear();\n        batchCount = 0;\n        batchExecutionUnits.clear();\n    }\n}\n","sourceCodeStart":225,"sourceCodeEnd":255,"githubUrl":"https://github.com/apache/shardingsphere/blob/e952770a215630a3659c75d64369168cd3e26b82/jdbc/src/main/java/org/apache/shardingsphere/driver/executor/engine/batch/preparedstatement/BatchPreparedStatementExecutor.java#L225-L255","documentation":"IllegalStateException thrown from BatchPreparedStatementExecutor.getParameterSets when no BatchExecutionUnit in batchExecutionUnits matches the given JDBCExecutionUnit by datasource+SQL. It signals an internal inconsistency between the routing result (execution units) and the batch parameter groups collected from addBatch() calls — a library-side invariant break, not normal input validation.","triggerScenarios":"Executing a batched PreparedStatement via JDBC driver when the rerouted JDBCExecutionUnit's dataSourceName/SQL pair does not isSameDataSourceAndSQL-match any collected BatchExecutionUnit — e.g. routing changed between addBatch and executeBatch, or inconsistent parameter metadata across batch rows.","commonSituations":"Mixing different SQL statements or different datasources in one batch object; reuse of a statement after clearBatch in a partial state; version regressions in the driver's batch routing; concurrency bugs where a statement is shared across threads.","solutions":["Ensure every addBatch() call on a PreparedStatement uses the same SQL and only parameters vary; never interleave different statements.","Call clearBatch() before starting a new batch cycle on a reused statement.","Do not share a single PreparedStatement/connection across threads for batch execution.","If SQL and datasources are consistent and it still fails, capture the statement SQL, parameter sets, and routing config and report it as a ShardingSphere bug; try upgrading to the latest patch release."],"exampleFix":"// before\nstmt.addBatch(\"INSERT INTO t VALUES (?)\");\nstmt.addBatch(\"INSERT INTO u VALUES (?)\"); // different SQL in one batch\nstmt.executeBatch();\n// after\nstmt.addBatch(); stmt.addBatch(); // same SQL via PreparedStatement, params only\nstmt.executeBatch();","handlingStrategy":"validation","validationCode":"// one statement, one SQL, params only\nif (batchSqlVariants > 1) throw new IllegalArgumentException(\"mixed SQL in batch\");","typeGuard":null,"tryCatchPattern":"catch (IllegalStateException ex) { rollbackTx(); clearBatch(); rethrowWithDiagnostics(); }","preventionTips":["Always addBatch() on the same PreparedStatement","clearBatch() before reusing a statement","Keep statement objects single-threaded","Report reproducible cases upstream with SQL and routing config"],"tags":["jdbc","batch","prepared-statement","internal-error"],"backgroundTag":null,"analyzedSha":"e952770a215630a3659c75d64369168cd3e26b82","analyzedAt":"2026-08-14T13:54:53.392Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}