How to call a report created with iReport

1

I have the following situation: I received several reports created by another developer, who used iReport. He sent me the files .jasper and .jrxml .

I have installed Eclipse Kepler with the JasperSoft plugin.

How can I trigger reports from a JFrame , where do I already have all the buttons to make these calls? I use MySQL as DB.

Could anyone give a help or an example?

    
asked by anonymous 01.07.2014 / 15:29

1 answer

4

Augusto,

You can do this as follows:

        Map parametros = new HashMap();
        String relatorio = "caminhodorelatorio\arquivo.jasper";
        JasperPrint jasperPrint = JasperFillManager.fillReport(relatorio, parametros);            
        JasperViewer view = new JasperViewer(jasperPrint, false);
        view.setVisible(true);

Being necessary to put the following imports in your class:

import java.util.HashMap;
import java.util.Map;
import net.sf.jasperreports.engine.JasperFillManager;
import net.sf.jasperreports.engine.JasperPrint;
import net.sf.jasperreports.view.JasperViewer;

edit: The variable "parameters" is a parameter of type Map, which must be passed in the fillReport method.

Inthisvariableyoucanaddvaluestobeusedinthereport,forexample:areporttitle

parametros.put("ReportTitle", "PDF JasperReport");
    
01.07.2014 / 15:51