我試圖使用jdbcTemplate執行存儲過程,但我不斷收到一個錯誤,指出GetEvents需要0個參數。任何人都可以闡明爲什麼還有更好的方法來執行這個存儲過程?在Java中執行MySQL存儲過程
我得到的錯誤是:
org.springframework.dao.InvalidDataAccessApiUsageException:SQL [CALL GetEvents(?,?,?)]:給定的3個參數,但預期0
步驟
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);
你有沒有設法找出你的調用問題? – Malvon