我得到以下em查询和例外:
public List<Service> findServicesFromHelperBetween(long idPerson, String from, String to) throws DAOException {
List<Service> servicesFromHelperBetween = new ArrayList<Service>();
try {
em.getTransaction().begin();
servicesFromHelperBetween = em.createQuery("SELECT S FROM Service S WHERE S.helper.idPerson = " + idPerson + " AND S.date BETWEEN " + from
+ " AND " + to).getResultList();
em.getTransaction().commit();
}
catch (Exception e) {
em.getTransaction().rollback();
throw ExceptionBuilder.findServiceFailedInDAO(e, Service.class);
}
return servicesFromHelperBetween;
}
例外:
Exception Description: Syntax error parsing [SELECT S FROM Service S WHERE S.helper.idPerson = 8 AND S.date BETWEEN 01.11.2014 AND 30.11.2014].
[71, 73] The identification variable '01' is not following the rules for a Java identifier.
[86, 88] The identification variable '30' is not following the rules for a Java identifier.
答案 0 :(得分:0)
尝试将参数放在单引号
之间em.createQuery("SELECT S FROM Service S WHERE S.helper.idPerson = " + idPerson + " AND S.date BETWEEN '" + from
+ "' AND '" + to + "'").getResultList();