{"record":{"id":"9fc3c7ef266556a5","repo":"prestodb/presto","slug":"no-value-specified-for-parameter","errorCode":null,"errorMessage":"No value specified for parameter ","messagePattern":"No value specified for parameter ","errorType":"exception","errorClass":"SQLException","httpStatus":null,"severity":"error","filePath":"presto-jdbc/src/main/java/com/facebook/presto/jdbc/PrestoPreparedStatement.java","lineNumber":810,"sourceCode":"        throw new SQLException(\"This method cannot be called on PreparedStatement\");\n    }\n\n    private void setParameter(int parameterIndex, String value)\n            throws SQLException\n    {\n        if (parameterIndex < 1) {\n            throw new SQLException(\"Parameter index out of bounds: \" + parameterIndex);\n        }\n        parameters.put(parameterIndex - 1, value);\n    }\n\n    private static List<String> toValues(Map<Integer, String> parameters)\n            throws SQLException\n    {\n        ImmutableList.Builder<String> values = ImmutableList.builder();\n        for (int index = 0; index < parameters.size(); index++) {\n            if (!parameters.containsKey(index)) {\n                throw new SQLException(\"No value specified for parameter \" + (index + 1));\n            }\n            values.add(parameters.get(index));\n        }\n        return values.build();\n    }\n\n    private void requireNonBatchStatement()\n            throws SQLException\n    {\n        if (isBatch) {\n            throw new SQLException(\"Batch prepared statement must be executed using executeBatch method\");\n        }\n    }\n\n    private static String getExecuteSql(String statementName, List<String> values)\n    {\n        StringBuilder sql = new StringBuilder();\n        sql.append(\"EXECUTE \").append(statementName);","sourceCodeStart":792,"sourceCodeEnd":828,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-jdbc/src/main/java/com/facebook/presto/jdbc/PrestoPreparedStatement.java#L792-L828","documentation":"Before executing, toValues() walks parameters 0..size-1 and requires every slot to be filled; a gap means at least one placeholder was never bound. Note the count-based check: if a higher index was set while an earlier one was skipped, the earlier one is reported. This prevents sending an incomplete parameter list to the Presto server.","triggerScenarios":"Executing (executeQuery/executeUpdate/executeLargeUpdate/execute/addBatch) a PreparedStatement where some setXxx call was skipped, or where parameters were set out of order leaving an earlier index unset while a later one was set.","commonSituations":"Conditional binding code that forgets a branch; N placeholders in SQL but only N-1 setters called; setting only parameter 3 in a 3-parameter statement (indexes 0 and 1 never filled); refactoring that removed a parameter from code but not the SQL.","solutions":["Count the ? placeholders in the SQL and call one setXxx for each index 1..N before executing","Check the message's parameter number to find the first missing binding and add the missing setXxx call","In dynamic/conditional code, ensure every branch binds the same full set of parameters, using setNull for absent values","Bind parameters in ascending index order to keep gaps from hiding behind later bindings"],"exampleFix":"// before\nps.setInt(1, id); // placeholder 2 never set\nResultSet rs = ps.executeQuery();\n// after\nps.setInt(1, id);\nps.setString(2, name);\nResultSet rs = ps.executeQuery();","handlingStrategy":"validation","validationCode":"int placeholders = sql.length() - sql.replace(\"?\", \"\").length();\nif (placeholders != boundParameterCount) {\n    throw new IllegalStateException(\"Expected \" + placeholders + \" bound parameters, got \" + boundParameterCount);\n}","typeGuard":null,"tryCatchPattern":"catch (SQLException e) {\n    if (e.getMessage().startsWith(\"No value specified for parameter\")) {\n        int missing = Integer.parseInt(e.getMessage().substring(e.getMessage().lastIndexOf(' ') + 1));\n        // bind parameter 'missing' before executing\n    }\n    throw e;\n}","preventionTips":["Count ? placeholders and bind exactly one value per index 1..N","Bind parameters in ascending order","In conditional binding, bind setNull(...) on branches where a value is absent","Update SQL and setter code together when parameters change"],"tags":["jdbc","parameter-binding","prepared-statement"],"backgroundTag":"jdbc-missing-parameter-binding","analyzedSha":"55bb57d202de3b926896fa966c2c4a44c779634e","analyzedAt":"2026-09-04T12:50:26.162Z","contentChangedAt":"2026-09-04T12:50:26.162Z","schemaVersion":2},"datasetVersion":"2026-09-11T21:17:09.523Z"}