Passing of double parameters to Jasper report

0

I'm making a report that passes as parameters:
Start date, end date and type (which can be: input, output or input and output).

Everything works fine until I try to get the report that gets input and output ... I've tried it in many ways and I can not get results.

Query on Jasper.

Javacode:

protectedvoidrelEntrada(HttpServletRequestrequest,HttpServletResponseresponse)throwsServletException,IOException{try{SessionImplementorsim=(SessionImplementor)HibernateUtil.getSessionFactory().openSession();Connectioncon=sim.connection();StringtipoMov=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();
    }
}
    
asked by anonymous 19.05.2017 / 20:40

2 answers

0

@sergioBertolazzo, you're really right, but one thing I was not calling was no! of p {} ... there would never go the way I wanted or do a ternary .... after I put p! {} everything was legal.

    
25.05.2017 / 19:40
1

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

If you look at your query it looks like this:

he.tipo = 'entrada or tipo = saida'

So, just change your parameter from:

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

To:

param.put("tipmov", "entrada or he.tipo = "+'"'+"saida"+'"');
    
22.05.2017 / 21:24