简体   繁体   中英

Querying a MySQL DataBase from JPA

I am working on a Java project. I want a query for mysql related to admission date having mapping between two modules student and attendance. Here's my code so far:

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();
}

I believe your query's fracture resides in the fact that you missed the condition.

You have to mention the column and the value in the WHERE clause.

In other words, student.admissionDate >= admissionDate and student.admissionDate >= admissionDate .

Here is how the query should look like (emphasize on the WHERE clause:):

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM