从JPA查询MySQL数据库

时间:2011-08-12 09:06:29

标签: java mysql sql java-ee jpa

我正在开发一个Java项目。我想要一个与入学日期相关的mysql查询,其中包括学生和出勤两个模块之间的映射。到目前为止,这是我的代码:

public List<Student> findStudentByDate(String admissionDate) {

   System.out.println("call findStudentMethd******************with this pattern"
        + admissionDate
        + "*********************************************");
   return em.createQuery("select student from Student student where student.admissionDate>='' AND < '' like '" + admissionDate + "'")
            .getResultList();
}

1 个答案:

答案 0 :(得分:0)

我相信你的查询的破裂在于你错过了这个条件。

您必须在WHERE子句中提及列和值。

换句话说, student.admissionDate &gt; = admissionDate student.admissionDate &gt; = admissionDate

以下是查询的外观(强调WHERE子句!):

  " SELECT student " +
  " FROM Student student " +
  " WHERE student.admissionDate >= '" + admissionDate + "'" +
  " AND   student.admissionDate <  '" + admissionDate + "'"