'jasper report show count on footer of a specific query

am very new to jasper report also I have tried looking at videos but can not seem to get this one concept basically there is this main query which i have

select * from table

which is populated in the details area however i want a second query

select count(*) from table where name = "tim"

and put the count on the footer

can this be done using jasper any tutorial to this concept or guidance would be helpful

  • to sum up the details area should show all the data where as the footer should only show counts of a few things.


Solution 1:[1]

You can only have one DataSet (therefore query) for the report. In your case this is your main report select * from table, which seems to be working well.

You have two options for adding the information you want:

  1. (and I would say the better option) is to add a variable $V{tim_count} which is configured as:
  • initial value 0
  • expression value "tim".equals($F{name}) ? 1 : 0"
  • calculation function sum

there are multiple ways to increment this variable, so I'll leave that with you. In the footer you would then add a text field with the $V{tim_count} variable as it's contents.

You can read about variables here https://community.jaspersoft.com/wiki/variables

  1. You can add an object that has it's own DataSet:
  • Table
  • List
  • Subreport

You would then be able to add your query to that object and display it appropriately. As you can see, displaying a COUNT is not really the most appropriate way to do this.

Note - I don't suggest this way

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 kendavidson