我有两个datepickers来自和到date.And然后一个文本框。选择日期并在文本框中键入一些名称我需要过滤表中的记录。我在我的表中有入场日期。我需要写查询,以便如果学生名称匹配,并且如果admissionDate介于fromdate和todate之间,那么它应该显示记录
我正在编写此查询,但它无效。
SELECT studentId, studentName, admissionDate
from Student
where studentName like :studentName
AND admissionDate BETWEEN (fromDate like :fromDate AND toDate like :toDate)
order by studentId desc
从DaoImpl我得到了从日期到日期值
DaoImpl
@Override
public List<Student> getSearchResultsByKeyword(String search,Date
fromDate,Date toDate) {
List<Student> users = new ArrayList<Student>();
System.out.println("Student Name:"+search+"fromDate:"+fromDate);
Query query =
sessionFactory.getCurrentSession().createSQLQuery(SEARCHSTUDENTS);
query.setParameter("studentName", "%"+search+"%");
query.setParameter("fromDate", fromDate);
query.setParameter("toDate", toDate);
/*query.setParameter("admissionDate","%"+search+"%");
query.setParameter("rollNumber","%"+search+"%");
query.setParameter("gender","%"+search+"%");*/
query.setResultTransformer
(Transformers.aliasToBean(Student.class));
users = query.list();
return users;
}
答案 0 :(得分:1)
尝试不使用此类
SELECT studentId, studentName, admissionDate
from Student
where studentName like :studentName
AND admissionDate >= :fromDate AND admissionDate <= :toDate
order by studentId desc
确保您发送的日期格式与DB日期格式相同(例如YYYY / MM / DD)