Jump to content
Changes to the Jaspersoft community edition download ×

iReport and parameters


Recommended Posts

Hey all,


I am evaluating iReports right now and this platform is foreign to me. I am familiar with Crystal Reports and M$ Report Services for 2000.


I have what I assume is a basic question. How do I utilize a parameter in an SQL statement? For example,

if I have a statement like:

Select * from orders

and I want to constrain by date:

select * from orders where dt >= (date) and dt <= (date)

How do I do it?


I have looked around and it does not seem to me to be clear. I would like to allow my customers to customize their reports based on parameters.


If someone could provide a simple example it would be greatly appreciated!




Link to comment
Share on other sites

  • Replies 9
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

im new to ireport too, just been digging it for 2 weeks :laugh:


anyway on the parameter thing in ireport MENU->VIEW->PARAMETER


add one parameter


here's an example on what u should fill



Parameter Name : ReportDate

Parameter Class Type : java.lang.date

Default Value Expression : "" (this is a default value if it's not given during run time)

Is for prompting : YES



Then in your sql just use something like this


SELECT * FROM table WHERE field=$P{ReportDate};



hope this helps


Link to comment
Share on other sites

Yup! That works :)

Thanks edxerx..


I also noticed that you can then use a parameter with the same name in the JasperReports server and you get the prompt on the page when you call up the report.


Ok... So far so good....


My next two things to tackle I think will be expressions and charts.





Link to comment
Share on other sites

  • 2 years later...

Hello All,

I am very new to Jaspersoft as well.

Is there a way to set a default value expression for Parameter Class Type: java.lang.date.

I tried "Jan 1, 2008" and "2008-01-01" but both values erred out as "can not cast string to date".

Please help!



Link to comment
Share on other sites

pjain's expression looks OK (and he tested it, so it must be valid).


But you may find these formats easier to use:
new java.util.Date()  // defaults to the current date
new SimpleDateFormat("yyyy-MM-dd").parse("2008-01-01")  // See SimpleDateFormat docs for lots of other possibilities



Link to comment
Share on other sites

  • 2 years later...

In your calling form..


Map reportParameters = new HashMap();

reportParameters.put("DATE", super.getDate("selected_Date"));


In iReport, assign parameter : DATE , class Type : java.util.Date


In iReport Query :

Where yourDataBaseFile.DateField = $P{DATE}


Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Create New...