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.