这是我的 jpql
@NamedQuery(name = "Subscribe.countByDate", query = "SELECT COUNT (s.idSubscribe) FROM Subscribe s WHERE s.dateInscription BETWEEN :dateS AND :dateF"),
这是我的门面:
public Number subSexeDate(String v, Date dated, Date datef) {
Query query = em.createNamedQuery("Subscribe.countByDate");
//query.setParameter("sexe", v);
query.setParameter("dateS", dated, TemporalType.DATE);
query.setParameter("dateF", datef, TemporalType.DATE);
return (Number) query.getSingleResult();
}
这是我的控制器
public List<Number> subSexeDate() {
sexe();
Date d1= new Date(2008-01-07);
Date d2= new Date(2010-01-01);
List<Number> nb = new ArrayList<Number>();
for (String var : sexe()) {
nb.add(ejbFacade.subSexeDate("homme", d1, d2));
}
return nb;
}
结果是:[0, 0]
真正的问题
Date d1 = new Date(2007-01-01); long x = d1.getTime(); long y = System.currentTimeMillis(); Date d2 = new Date(); d2.setTime(y); d1.setTime(x); List<Number> nb = new ArrayList<Number>(); for (String var : sexe()) { nb.add(ejbFacade.subSexeDate(var, d1, d2)); System.out.println(d1.toString()+"date2"+d2);}
但 system.out 的结果:信息:Thu Jan 01 01:00:02 CET 1970date2Sun May 26 11:55:31 CEST 2013 –</p>