An error occurs while executing a request for getting the number of records.

Error querying database. Cause: java.sql.SQLException: Parameter index out of range (1> number of parameters, which is 0).
The error may involve dataAccess.PhoneRecordMapper.getCountOfRecords-Inline
Occurred while setting parameters
Cause: java.sql.SQLException: Parameter index out of range (1> number of parameters, which is 0).

The request itself, in which an error occurs (moreover, when the request is executed on the server, and not through the code, everything works fine)

<select id="getCountOfRecords" resultType="java.lang.Integer" parameterType="hashmap"> SELECT COUNT(*) FROM t_call LEFT JOIN t_event ON t_call.ID_CALL = t_event.CALL_ID </select> <resultMap type="phoneRecord" id="phoneRecordMap"> <id property="recordId" column="RECORD_ID"/> <result property="recordId" column="RECORD_ID"/> <result property="recordEventId" column="RECORD_EVENT_ID"/> <result property="recordDate" column="RECORD_DATE"/> <result property="caller" column="CALLER"/> <result property="reciever" column="RECIEVER"/> <result property="callId" column="CALL_ID"/> <result property="idCall" column="ID_CALL"/> </resultMap> 

interface method:

 public int getCountOfRecords(HashMap<String, Object> param); 

If you just get all the records through the code, then everything is OK, and the records are obtained. Can someone suggest what could be the problem? Entries get in the Struts action.

  • one
    you have parameterType = "hashmap". can this be the case? - Mikhail Vaysman
  • Well, this can not be a problem. In other requests, too, used, and there were no problems. - Mikhail48
  • @ Mikhail48 remove parameterType from xml + check method name and method signature in interface. - Artem Konovalov
  • @ArtemKonovalov So yes, it works. But in the future, the WHERE block will be added to the query itself, and for it I pass the values ​​via hashMap. And in this case - everything crashes. - Mikhail48
  • what method in the interface? complete the question - Artem Konovalov

1 answer 1

The count request with parameters in mybatis looks like this:

  <select id="countByExample" parameterType="ru.izebit.model.MySuperModelExample" resultType="java.lang.Integer"> select count(*) from my_super_table <if test="_parameter != null"> <include refid="Example_Where_Clause"/> </if> </select> 

where MySuperModelExample is an object containing request parameters. It is not necessary to write it manually, it is generated by maven plugin mybatis-generator-maven-plugin

  • And if without a plugin? I just can't use it. ( - Mikhail48