我有兩個datepickers從和日期。然後一個textbox.After選擇日期並在文本框中鍵入一些名稱我需要篩選表中的記錄。我有入場日期在我的表。我需要寫查詢,以便如果學生名稱匹配,並且如果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我越來越沒有fromdate和todate值
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;
}
什麼意思由*不工作*。你有什麼錯誤嗎? –
你的BETWEEN是很奇怪的... – jarlh
我越來越錯誤在SQL語法 –