gpt4 book ai didi

mysql - 在两个日期之间搜索的查询

转载 作者:行者123 更新时间:2023-11-29 08:16:52 26 4
gpt4 key购买 nike

大家好,我有一个搜索查询,它应该显示设定日期范围内的所有结果

查询:

public List<Appointment> appointmentRangeSearch(Date startdatetime, Date endDate) {
Query q = em.createQuery("SELECT u FROM Appointment U WHERE u.startDatetime BETWEEN : date1 AND : date2 ");
q.setParameter("date1", startdatetime, TemporalType.TIMESTAMP);
q.setParameter("date2", endDate, TemporalType.TIMESTAMP);
return q.getResultList();
}

它返回错误:

Caused by: Exception [EclipseLink-0] (Eclipse Persistence Services - 2.5.0.v20130507-3faac2b): org.eclipse.persistence.exceptions.JPQLException
Exception Description: Syntax error parsing [SELECT u FROM Appointment U WHERE u.startDatetime BETWEEN : date1 AND : date2 ].
[34, 77] The expression is not a valid conditional expression.

表中的数据存储:

2013-12-15 00:00:00.0

我怎样才能完成这个搜索?

谢谢大家

最佳答案

: date1 中删除 :date1 之间的空格。所以你的查询应该是这样的:

SELECT u FROM Appointment U WHERE u.startDatetime BETWEEN :date1 AND :date2

关于mysql - 在两个日期之间搜索的查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20424590/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com