1 Reply Latest reply on Oct 28, 2005 1:38 PM by Emmanuel Bernard

    EJB QL Query with Date and between

    kourosh bagheri Newbie

      Hi!,

      could someone -please - give an example of a query, using the EJB QL
      between and parameters.

      My problem:
      I woul like to use this, to compute the sales of an year like this:


      public Collection<Order> getAllOrdersOfYear(String year) {
      
      float totalSales = 0.00F;
      String firstDayOfYear = year + "-01-01";
      String lastDayOfYear = year + "-12-31";
      try {
       //select sum(o.total)
       Query query = manager.createQuery("from Order o where o.orderDate between "
       + ":firstDayOfYear and :lastDayOfYear");
       query.setParameter("first", "'" + firstDayOfYear + "'");
       query.setParameter("last", "'" +lastDayOfYear + "'");
      
       return query.getResultList()) ;
      ...



      Could somebody please help me!!
      Why doesn't it work?