【问题标题】:org.springframework.dao.InvalidDataAccessApiUsageException: Parameter with that position [2] did not existorg.springframework.dao.InvalidDataAccessApiUsageException:具有该位置 [2] 的参数不存在
【发布时间】:2019-06-28 18:10:00
【问题描述】:

我正在尝试运行一个。我有一个查询的 SpringBoot 中的 API 程序。 以前它显示我解决的 parseException 错误,但现在出现了这个新错误。 这个问题在其他查询中从未出现过,我不知道问题是什么。请帮忙。

@Query(value="SELECT * FROM tbl_abc WHERE UserId = ?1 AND EndTime != '' AND StartDate BETWEEN '?2' AND '?3' ORDER BY StartDate ASC,StartTime",nativeQuery = true)
List<abc> getabctLog(int userId, String fromdate1, String todate1);

我希望从表格中获得查询中给出的条件的详细信息列表。但我收到了这个:

org.springframework.dao.InvalidDataAccessApiUsageException: Parameter with that position [2] did not exist; nested exception is java.lang.IllegalArgumentException: Parameter with that position [2] did not exist

【问题讨论】:

  • 任何关于使用'?2' 而不使用?2 的原因,它都会自动转换为'some value'
  • 好吧,我对 STRING 值使用单引号,即 '?2' 和任何整数仅 ?2。如果我删除字符串值的单引号,则会出现此错误:java.lang.IndexOutOfBoundsException: Index: 0, Size: 0

标签: java mysql spring-boot spring-data-jpa


【解决方案1】:

我认为您的 StartDate 是 Date 类型,但您输入了一个字符串。您需要更改代码:

@Query(value="SELECT * FROM tbl_abc WHERE UserId = ?1 AND EndTime != '' AND StartDate BETWEEN '?2' AND '?3' ORDER BY StartDate ASC,StartTime",nativeQuery = true)
List<abc> getabctLog(int userId, Date fromdate1, Date todate1);

【讨论】:

    猜你喜欢
    • 2016-09-11
    • 2019-03-06
    • 2015-11-22
    • 2018-07-05
    • 2017-10-03
    • 1970-01-01
    • 2017-07-29
    • 2015-03-12
    • 2016-09-15
    相关资源
    最近更新 更多