Passing full sql query as parameter in jasper reporting

I want to pass the whole sql query as a parameter to the jasper report. I tried using $ P {QUERY} but it gave me a mysql syntax error exception. And I want this to be passed at runtime. Does anyone know how to do this?

Sample code:

try {
        Map<String, Object> map = new HashMap<>();
        Connection conn = DatabaseConnection.getInstance().getConnection();

        map.put("QUERY", "Select u.name, u.status from user_info u where u.user_name = 'Thanuj'");

        JasperReport report = JasperCompileManager.compileReport("report1.jrxml");
        JasperPrint jp = JasperFillManager.fillReport(report, map, conn);
        JasperViewer.viewReport(jp, false);
    } catch (JRException ex) {
        Logger.getLogger(ReportTest.class.getName()).log(Level.SEVERE, null, ex);
    } catch (SQLException ex) {
        Logger.getLogger(ReportTest.class.getName()).log(Level.SEVERE, null, ex);
    } catch (ClassNotFoundException ex) {
        Logger.getLogger(ReportTest.class.getName()).log(Level.SEVERE, null, ex);
    }

      

+3


source to share


1 answer


I came up with an answer with some help from a colleague of mine. I had to change the ($ P {QUERY}) parameter to ($ P! {QUERY}) in the jasper report XML file (ex. Report.jrxml)



enter image description here

+2


source







All Articles