I'm trying to execute a stored procedure using jdbcTemplate but I keep getting an error saying that GetEvents expects 0 arguments. Can anyone shed some light on why or is there a better way to execute this stored procedure?
The error I'm getting is:
org.springframework.dao.InvalidDataAccessApiUsageException: SQL [CALL GetEvents(?, ?, ?)]: given 3 parameters but expected 0
Procedure
mysql> CREATE PROCEDURE GetEvents(IN search_table VARCHAR(255), IN start TIMESTAMP, IN end TIMESTAMP)
-> BEGIN
-> SELECT COUNT(*)
-> FROM search_table
-> WHERE time >= start AND time <= end;
-> END //
Query OK, 0 rows affected (0.02 sec)
Java
public int getEnterExitsAll(DateTime start, DateTime end) {
Map<String, String> params = new HashMap<String, String>();
params.put("search_table", TABLE_ENEX);
params.put("start", start.toString());
params.put("end", end.toString());
return template.queryForInt("CALL GetEvents(?, ?, ?)", params);
I suspect, it's happening because of your variable naming ( end
being reserved keyword). Please try renaming end
to endTime
and start
to startTime
or something similar.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.