Tuesday, April 29, 2008

How to Execute a SQL Query using iReport.


Click Data --> Report Query. The Following window will appear

Type the SQL Query you want. To pass Parameters user $P{PARAMENTER_NAME} (in iReport 2.0 or higher). You can click the “Automatically Retrieve Fields” check box to retrieve the fields.

Keep in mind if there’s an SQL error the fields will not be retrieved and the SQL error will be displayed.

You can also select the fields you want from a Database Model and generate the Query automatically. I DO NOT recommend this. Although you can set the conditions before hand I always find it reliable when I have a working Query in my hands. It’s always better to know that the query works. So create the query using SQL Navigator or a similar tool using sample data for “Parameters” and use that query.

Click OK after Fields are retrieved.

3 comments:

Anonymous said...

I have an ireport query where I just need to present a new field on a report - I've added the field to the select statement and when the report runs there is no data in the report, however if I run the report without the new field I get data. I know there is data in the field that I want to see so why would something so simple be causing me to not get any data in my report. Very Very frustrated. Any help will be greatly appreciated.

Anonymous said...

Sir,
i have 2 Queries in Jasper Reports .
1 is for SQL Server and 1 for Oracle, I want to write Conditional based selection in Report Query Window to select the Query for execution like :

param1:Contains the DB type expr. and the default is SQL DB.
and in the report Query if i write

if(param1=SQLSEREVER)
Begin
SQL QUERY EXPR.
Else
Oracle Query expr.
End .

But the same is giving the error .

Would you please tell/suggest any other way of doing it .or the proper Syntax of doing it

regds
Rakesh
Jasper Reports Developer

Unknown said...

Good question Rakesh. Any help?

Post a Comment