Switching from double parameters to Jasper report

Asked

Viewed 70 times

0

I’m making a report that passes as parameters:
Start date, end date and type (which may be: in, out or in and out).

Everything works fine until I try to get the report that takes in and out... I’ve tried many ways and I can’t get results.

Query in Jasper.

inserir a descrição da imagem aqui

Java code:

protected void relEntrada(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    try{
        SessionImplementor sim = (SessionImplementor) HibernateUtil.getSessionFactory().openSession();
        Connection con = sim.connection();

        String tipoMov = request.getParameter("tipMov");

        String dataini = request.getParameter("dataini");
        String dtini[] = dataini.split("/");
        String diai = dtini[0];
        String mesi = dtini[1];
        String anoi = dtini[2];

        String datafim = request.getParameter("datafim");
        String dtfim[] = datafim.split("/");
        String diaf = dtfim[0];
        String mesf = dtfim[1];
        String anof = dtfim[2];

        HashMap param = new HashMap();
        param.put("dataini",  anoi +"-"+mesi+"-"+diai + " 00:00:00" );
        param.put("datafim", anof +"-"+mesf+"-"+diaf + " 23:59:59" );

        if (tipoMov.equalsIgnoreCase("entrada")) {
            param.put("tipmov", "entrada" );
        } else if(tipoMov.equalsIgnoreCase("saida")) {
            param.put("tipmov", "saida" );
        } //else if(tipoMov.equalsIgnoreCase("entradaesaida")) {
            //param.put("tipmov", "entrada or tipo = "+'"'+"saida"+'"');
        //}

        InputStream arquivo = getServletContext().getResourceAsStream("/relatorios/RelMoviment.jasper");

        byte[] pdf = JasperRunManager.runReportToPdf(arquivo, param ,con);

        ServletOutputStream out = response.getOutputStream(); 
        out.write(pdf);
        out.flush();
    } catch(Exception e) {
        e.printStackTrace();
    }
}

2 answers

1

If everything is working fine, and the error only occurs when you pass the two parameters, your error is in the query.

If you look at your query this getting like this:

he.tipo = 'entrada or tipo = saida'

then, just change your parameter of:

param.put("tipmov", "entrada or tipo = "+'"'+"saida"+'"');

for:

param.put("tipmov", "entrada or he.tipo = "+'"'+"saida"+'"');

0


@sergioBertolazzo , really you are right, but one thing I was not calling me was in ! do p{}... then it would never go the way I wanted or make a ternary.... after I put p!{} everything became legal.

Browser other questions tagged

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