I am just starting learning
Jasper reports with
Java. I searched through the web and did not find a good tutorial which teaches reporting from the very beginning. Tutorialspoint.com have a good one, but they use
ANT for that. I can learn them after, but what I need now is to generate
jasper reports using simple Java programs. I found a code from
github which is here, but I have some issues with understanding that code.
String reportName = "myreport"; Map<String, Object> parameters = new HashMap<String, Object>(); connection = new ConnectionFactory().getConnection(); // opens a jdbc connection // compiles jrxml JasperCompileManager.compileReportToFile(reportName + ".jrxml"); // fills compiled report with parameters and a connection JasperPrint print = JasperFillManager.fillReport(reportName + ".jasper", parameters, connection); // exports report to pdf JRExporter exporter = new JRPdfExporter(); exporter.setParameter(JRExporterParameter.JASPER_PRINT, print); exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, new FileOutputStream(reportName + ".pdf")); // your output goes here exporter.exportReport();
It generates the report using above code. But, there are some parts where I find some issues when understanding.
- Where is the Query String?
- Do I have to create the
jrxmlfile separately, which contains the query string and name that file as