Date format in select

Asked

Viewed 90 times

0

I have this method:

    public List<LoteEnvEntity> findallByDate(java.util.Date dataDe, java.util.Date dataAte) {
    String strQuery = "SELECT L FROM LoteEnvEntity as L WHERE 1=1";
    //SimpleDateFormat simpledate = new SimpleDateFormat("yyyy-dd-MM");
    Query query = getEntityManager().createQuery(strQuery);     
    if (dataDe != null)
    {
        strQuery += " and L.dateEnvio >= :dataDe";// + simpledate.format(dataDe);
        query.setParameter(":dataDe", dataDe);
    }

    if (dataAte != null)
    {
        strQuery += " and L.dateEnvio <= :dataAte"; //+ simpledate.format(dataAte);
        query.setParameter(":dataAte", dataAte);
    }           

    return (List<LoteEnvEntity>) query.getResultList();     
} 

Only on the console an error appears on Convert date as the date comes in the following format: "Wed Nov 05 00:00:00 BRST 2014". And I need to use it in the select of the Entity, as you can see I’ve tried using the SimpleDateFormat.

1 answer

1

Use the following code:

query.setParameter("dataDe", dataDe, TemporalType.DATE);
  • 4

    If your answer actually solves the problem, if possible, explain it better.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.