Search code examples
javamysqlpostmanibatis

Binding Exeception parameter error while collecting data from Mysql


I'm fetching the Mysql data from the table by using the below code:

public class NagaGetVariableValuesMapper extends NagaStringMapper {
    private String variableName;
    private String variableValue;

    public NagaGetVariableValuesMapper(String variableName,String variableValue) {
        this.variableName = variableName;
        this.variableValue=variableValue;
    }

    public CustomSqlExecution<WorkflowValuesMapper, List<Map<String, Object>>> buildExecution() {
        return new AbstractCustomSqlExecution<WorkflowValuesMapper, List<Map<String, Object>>>(WorkflowValuesMapper.class) {
            public List<Map<String, Object>> execute(WorkflowValuesMapper customMapper) {
                return customMapper.nagaFindVariable(variableName, variableValue);
            }
        };
    }

    @Override
    public List<WorkflowResultDisplayObject> processResults(List<Map<String, Object>> results) {
        return processResults(results, "variableName","variableValue");
    }
}

and the mapping file is here

@Select({ "select *  from ACT_RU_VARIABLE var inner join ACT_RU_TASK task on var.PROC_INST_ID_ = task.PROC_INST_ID_ "
            + "where var.TEXT_ = #{variableName} and var.NAME_ = #{variableValue}"})
    List<Map<String, Object>> nagaFindVariable(String variableName, String variableValue);

But when I'm trying to fetch the data, I'm getting the below error:

Error querying database. Cause: org.apache.ibatis.binding.BindingException: Parameter 'variableName' not found. Available parameters are [0, 1, param1, param2]

Cause: org.apache.ibatis.binding.BindingException: Parameter 'variableName' not found. Available parameters are [0, 1, param1, param2]


Solution

  • Try to add annotation @Param as below with this import.

    import org.apache.ibatis.annotations.Param;
    
    List<Map<String, Object>> nagaFindVariable(
       @Param("variableName") String variableName, 
       @Param("variableValue") String variableValue
    );
    

    Don't forget use correct import. If you use wrong import, your error will be same.

    Refer to: nested exception is org.apache.ibatis.binding.BindingException: Parameter 'tagId' not found. Available parameters are [0, 1, param1, param2]