0

I am creating a java web application with jasper reports. In that project I have to create some reports. So far I managed to generate a report which have a specific query that is attached to the report itself with the following code.

Connection conn = util.db.getDbConnection();
String reportPath = "C:/test.jrxml";
JasperReport jr = JasperCompileManager.compileReport(reportPath);
JasperPrint jp = JasperFillManager.fillReport(jr, null, conn);

File outDir = new File("D:/jasperoutput");
outDir.mkdirs();

JasperExportManager.exportReportToPdfFile(jp, "D:/jasperoutput/test.pdf");

System.out.println("Done!");

The above code is working perfectly. Now I want to pass a SQL Query as a string when creating the report. Can someone please help me with this. Thank you.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
jayz
  • 401
  • 1
  • 5
  • 25
  • you should pass java bean instead of SQL query to report. step 1 get data via SQL, step 2 pass data to bean and pass bean to report. – Ye Win Nov 09 '16 at 05:57
  • 1
    Possible duplicate of [JasperReports: Passing parameters to query](http://stackoverflow.com/questions/11871042/jasperreports-passing-parameters-to-query) & [optional where clause jasper reports](http://stackoverflow.com/q/19401825/876298) & [can we pass an sql query string as a param into report?](http://stackoverflow.com/q/7254149/876298) – Alex K Nov 09 '16 at 07:29

0 Answers0