Create iReport variable for database

Asked

Viewed 510 times

1

I need to create a report of the selected month with the information contained in the database, for this I intend to create a variable in iReport that receives the month (by netbens) which will be compared with the existing sql in Ireport that is directly connected to the bank.

Metrodo iReport:

public void imprimir() {
    try {

        JasperPrint print = JasperFillManager.fillReport("C:\\Users\\costa\\OneDrive\\Documentos\\NetBeansProjects\\Relatorio\\Estoque.jasper", null, conexao);

        JasperViewer.viewReport(print, false);

    } catch (Exception e) {
        JOptionPane.showMessageDialog(null, e);
    }
}

SQL present in iReport:

select * from Hospede h where DATE_FORMAT(h.horaini,'%m') = variavel
  • Is there an error? What is your question?

1 answer

2


In this case you will have to create a parameter. In iReport do the following:

inserir a descrição da imagem aqui

It will create a new parameter named "parameter1", you will need to go into properties and edit its name and type.

To use it in your query the notation will be the following $P{parameter name}

select * from Hospede h where DATE_FORMAT(h.horaini,'%m') = $P{nomeparametro}

In java code:

HashMap params = new HashMap<>();
params.put("nomeparametro", parametro);
JasperPrint print = JasperFillManager.fillReport("C:\\Users\\costa\\OneDrive\\Documentos\\NetBeansProjects\\Relatorio\\Estoque.jasper", params, conexao);
  • Thank you very much if you know any tutorial on iReport to tell me would be of great help

Browser other questions tagged

You are not signed in. Login or sign up in order to post.