pass list of objects instead of SQL query

0

I have a list of Employee in my java application.

    List employee = new ArrayList();

Instead of passing the SQL query (select * from employee) to iReport, I want to pass my list.

    Map map = new HashMap();
    map.put("queryReport","select * from EMPLOYEE");
    JasperPrint jp = JasperFillManager.fillReport(input,map,connection);
    JRExporter exporter = new JRPdfExporter();
    exporter.setParameter(JRExporterParameter.OUTPUT_FILE_NAME, output);
    exporter.setParameter(JRExporterParameter.JASPER_PRINT, jp);
    exporter.exportReport();

It would be great if someone can help me with the code which I have to use.

ghr_60's picture
2
Joined: May 25 2013 - 3:56am
Last seen: 6 years 6 months ago

1 Answer:

0

don't understand exactly what you're trying to do... if you want to pass an object collection to your report, you will have to design a bean class first, like:

then fill your list with the bean objects:

List employee = new ArrayList();

employee.add(new MyEmployeeBean(...constructor needed...)

finally create a bean datasource and pass it to the report, e.g.:

JasperPrint jp = JasperFillManager.fillReport(..., ..., new JRBeanArrayDataSource(employee));

have a look here:

http://jasperreports.sourceforge.net/sample.reference/datasource/

Cheers, Thomas

http://www.thomaszimmer.net

Thomas Zimmer's picture
Joined: Oct 2 2012 - 1:35am
Last seen: 5 days 13 hours ago

Thanks Thomas. It helped me a lot.

ghr_60 - 6 years 6 months ago
Feedback
randomness