1

I need to send parameters to my JasperReport.

Do I compile it first using compileReport and then call the fillReport passing the parameters or do I need to do things in the opposite order?

sclv
  • 38,665
  • 7
  • 99
  • 204
Chetan
  • 39
  • 6
  • 1
    Generally, unless you are dynamic generating the structure of the report, you should compile once, maybe during your applications build cycle, and simply load and fill it at runtime – MadProgrammer Mar 21 '16 at 02:13
  • Do you mean to set my Parameters and invoke the fillReport Method when you said fill? – Chetan Mar 21 '16 at 02:32

1 Answers1

2

Compiling and filling report are two different things.

About compiling

Jasper reports is normally developed using IDE tools like iReport or JasperSoft Studio (you can also use a notepad), the report is saved in a file with the extension .jrxml, before running the .jrxml you need to compile it into a .jasper file (you can also compile on run time and only keep the JasperReport object)

It can be compared with the .java file that need's to be compiled into .class files before you can run the program.

For more information see:

How do I compile jrxml to get jasper?

About filling

Filling is when you like to fill your report design with data, the data can come from a JRDatasource or a database Connection (query in report) and a Map<String,Object> parameter map. When report is filled you get a JasperPrint object (even this can be saved to file, to avoid filling same report multiple times)

About export

The final process in report generation is the export process, where you export the JasperPrint to your desired format pdf, excel, html etc.

So lets get back to your original question.

Do I compile it first using compileReport?

You can if you like to but you do not need to if you have already compiled your report, in this case just load the compiled report which is faster.

JasperReport jasperReport = (JasperReport) JRLoader.loadObject(inputStream);
Community
  • 1
  • 1
Petter Friberg
  • 21,252
  • 9
  • 60
  • 109