Sometimes we need to pass one or more parameters to our report. For example, we may need to generate a report for some items with a spesific category or price. Based on our previous tutorial, we're going to make a report to view the contacts list with a certain address. For this tutorial, you have to create a new report.
Adding New ParameterYou need to specify address as a parameter, so click on View menu, then click Parameters. Click New to add new parameter. Give a name for your new parameter and specify its data type. For example, I give the name PRM_ADDRESS for this parameter and its data type is String. After that, give a check mark on Use as a prompt option. You can see the picture below for a clearer information.
Create Report QueryAfter you create a new parameter, you have to create report query based on that new parameter. How we do this? Click on Data menu, then click on Report Query. In the query text box, type this SQL command: SELECT * FROM contact WHERE address=$P{PRM_ADDRESS}.
As you can see the $P{PRM_ADDRESS} represents the parameter that you've made before.
After that, you have to design the report. The report's layout is up to you now. I will not talk about how to design the report here because I have talked about it in the previous tutorial.
Write Your CodeLet's write the code! Same like the previous tutorial, I'll give you all the code so you can copy-paste and modify it if necessary.
Execute It!
Final step is execute your program. Don't forget to set the CLASSPATH. If you forget how to do that, you can see the previous tutorial right before this one.