It may be a silly question but I have not been able to solve the problem I have the following methods:
public long contarPedidosMeses(int cedulaCliente, int codigoProducto, Date fechaIni, Date fechaFin){
Query q;
q = em.createNativeQuery("SELECT COUNT(*) FROM pedidos, pedidoproducto WHERE fechaDeSolicitud BETWEEN ? AND ? and pedidos.cedulaCliente=? and pedidoproducto.codigoProducto=? and pedidos.idPedido= pedidoproducto.idPedido");
q.setParameter(1,fechaIni);
q.setParameter(2, fechaFin);
q.setParameter(3, cedulaCliente);
q.setParameter(4, codigoProducto);
long valor=Long.parseLong(q.getSingleResult().toString());
return valor;
}
public long valoresMeses(Date fechaI, Date fechaF, int cedula, int codigo){
long valores= productosf.contarPedidosMeses(cedula, codigo, fechaI, fechaF);
return valores;
}
The problem I have is that I do not know how to pass the Date data when calling the method. Therefore, the query does not work for me.
I have treated it in the following way:
controladorProducto.valoresMeses('2016/01/01', '2016/01/31', controladorUsuario.objUsuarioLogin.idUsuario, 1)
Also changing the place of the numbers ie (dd / mm / yyyy), but it does not work either. In the method valuesMeses () I have changed that I do not receive a Date but a String and I try to convert it with SimpleDateFormat but it sends me a very different date when I convert it. I do not know what else I would really appreciate your help.
I work on jsf, JPA and the MySQL database.