Chetan
Chetan

Reputation: 39

JasperReport... What do you do First Compile or fill using parameters?

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?

Upvotes: 1

Views: 1857

Answers (1)

Petter Friberg
Petter Friberg

Reputation: 21710

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);

Upvotes: 2

Related Questions