How to Pass Parameters in JasperReports

0

Hello everyone, good afternoon, I have a question that is killing me. I have a project that has to print a report that contains two lists and two tables. My problem is this, I'm not intresting how jasper interprets the data that is passed to it, because of the following:

In my report the first time I did, in jasper studio I created the report with a fixed bank there everything worked perfectly, and then I passed that report to java, there when I ran the code the report was generated with the bank that was created in jasper studio and not with the data passed by java.

So I changed the report and there came more doubts, because I switched to using parameters and created lists and tables without a database, but the report does not even appear, even though I pass the parameters through java. My question is how does jasper interpret this data that I am passing, type, in my code I pass the connection of the bank that I am using, is it even necessary to pass it since I pass the information by parameter?

asked by anonymous 02.06.2018 / 02:01

2 answers

0

First on the connection to the database.

Because you have to pass a connection in this case, when you are creating a report, it is usually created according to the information of the database you want to display, so when you are creating a report in tools like JasperStudio you create a connection to make the tests with the actual data.

Then when you are going to generate the report you need to send the connection to Jasper to know where to get the data.

In fact Jasper works as follows, you usually create a report in a software such as JasperStudio. Inside it you have several options to build your report like adding fixed texts or images and so on as you wish and inside it there is also a parameter option.

YoucreateaparameterthatcanbeusedasyousaidinQuerysSQLandtosettheseparametervaluesispassedHashMapwiththeparametersasyouarealreadydoing.

Forexample,let'ssayyoucreatedaparametercalled"ID", to assign the value to it in your hashMap, you set the value as follows.

When your report is generated it will use this value passed in your report.

parametros.put("ID","VALOR")

If you have any questions here, there is a good example: report example

    
03.06.2018 / 03:02
0

Thanks for the explanation, I've been researching since I put the question here and together with your explanation I understood what I was doing wrong. But I still did not solve my problem. I'll try to explain better. I have a personal financial management system, and I want to make available a report that contains the user's accounts and cards as well as the debts related to them, as well as two graphs with the categories the user spent the most.

The strategy I used to create the report was to put the list element to list the accounts and cards and inside it I put a table with the debits. In the datasets of the elements I put querys with parameter only that I can not pass the data to these parameters. I do not know if I'm using the correct strategy or not, because I've never used jasper before, so I'm pretty confused as to why this information in the report.

If you have any suggestions on how to better organize or assemble the report, I would appreciate it.

    
03.06.2018 / 04:12