Jasperreport parameter selection from SQL query - jasper-reports

I wanted to create a JasperReport which asks the user for a deliverer before it creates a report with data of the last the deliveries of the selected deliverer.
The problem, how I can do that? I found only examples where a parameter is created and the ArrayList is filled statically. But in my parameter I need the query result over the table of deliverers filled.
Can anybody tell me a possible solution?
I'm using Jaspersoft Server 5.1 which directly access a PostgreSQL database which has a datawarehouse structur. So it's not possible to use Java code.

Here is the documentation for adding input controls to reports in JasperReports Server:
http://community.jaspersoft.com/documentation/jasperreports-server-user-guide/adding-input-controls
Scroll down to the section that deals with query-based input controls. Your input control will have a name, such as deliverer. In your report, you must add deliverer as a parameter and reference it in your query, as you have done in your comment.

Related

How to define and use a parameter in Jasper Studio that is a set of ids?

Does anyone know how to define a parameter in Jasper Studio (Community version 6.3.1 final) that is a collection, such as a Set, and to use that in a postgresql query? For example, this Set could be a set of ids that would then be used in the query.
I do a simple sql query like:
select pg_typeof($P{companyDepartmentIds}) as type
I get the following error after selecting "Read Fields":
It seems like this should be possible, I feel I am missing something. I am not sure where in the Jasper Studio interface I can call this setObject() function. Anyone have any thoughts here?
If defining a collection of parameters can't be done, the only other thing I could think of is I could have the parameter be a String, but it would be understood it would be a comma delimited list of values, then I could use regexp_split_to_table or regexp_split_to_array within the query itself.
I was directed to this link and saw what I needed here:
https://community.jaspersoft.com/blog/tip-multi-select-query-integer-parameter-japser-ireportstudio
Specifically what I was looking for was this part from the website under the "Correct Way:" example
SELECT * from table where $X{IN,id,companyDepartmentIds}

Override sql database field values while filling a report in Jasperreports

I've the following code to fill a report in JasperReports by passing some parameters and a postgresql database connection:
JasperFillManager.fillReport(report, jasperFillManagerParameters, sqlConnection);
The database is a third-party DB and I can't make any change on it, I also can't change report template (jrxml file); But I need to modify values of some fields while filling the report (e.g. some date convertions), so the only place I can make my changes is when I fill the report using above code.
I know that I need to work with JasperFillManager (e.g. override some of its aspects) to achieve this goal, but I don't know how should I exactly do this. Any suggestion would be appreciated.

Get List of Values (LOV) from sql query in JasperReport

In Oracle Reports I am able to run reports which get parameters by querying from database. In PHP/mySQL I am able to populate data in HTML dropdown menu by using sql query.
I would like to do the same in my JasperReports, either using JasperReport Studio or using JasperReport Server input controls. The current LOV I am able to get using JReport 'Input Controls' makes me enter options manually.
This is what I am trying to explain in words:
You can do this with an Input Control in JasperServer. When in the Create Input Control page of the wizard choose a Type of Single-select Query. This will enable you to enter a SQL query so you can provide a list of options from the database.
There is also a Multi-select Query alternative.

How to make my subreport access a different database than the main one?

I am evaluating JasperReports and Jaspersoft Studio for using in the company I work for and I am trying to build a report that contains information from 2 different databases.
I have 2 data adapters configured.
I've my research and found out that the only way to do so is to have either a list, table or subreport in a main report, but I still can't make it work.
I took the subreport approach, I have two reports that work separately, the main one executes this query in the sample DB
select 1 from ORDERS limit 10
The subreport runs this one in a Vertica database I own:
select 1 from my_schema.my_table limit 10
Both of them, as said, run separately.
So I go to the mainreport and add a SubReport element to the ColumnHeader band, then the wizard opens:
In the step 1 I select the subreport from the project
Second step is connection. I have these options:
Same JDBC conection
Use another connection
Use an empty data source
Use a JRDatasourceExpression
Don't use any connection.
The first and third ones are not what I want.
I tried to set the second one, but I could not find a way to select the data adapter that I have configured.
The last one doesn't work ( I get a message saying that my_schema doesn't exists, so I think that it is still trying to access the MainReport database).
Is there anyway I can make a subreport run a query in a different database/datasource from the main report?
I can summarize what I did if anyone has the same issue:
I made a proof of concept (therefore I do not have the code anymore), but I created a JRDataSource class using this tutorial and there I manually access the database and returned the rows. Then I use this as the datasource of my subreport/table.
Not as nice as I wanted, but it is possible
I guess this iReport article is also applicable to reports designed in jaspersoft studio; you just need to define the subreport connection parameter with the given expression.
Perhaps, you can ask for help from two parameters which defined in the master report by yourself. Such as:
$P{MySubreport} with type net.sf.jasperreport.engine.JasperReport;
$P{MyDatasource} with type net.sf.jasperreport.engine.JRDataSource;
Associate these two parameters to your subreport element respectively in attributes 'Expression' and 'Data Source Expression';
Please write your DataSource class that implements interface JRDataSource.
Then, in your servlet class, put your real parameter values(JasperReport for your subreport .jasper file, and your DataSource object) into a parameters Map object, and call JasperFillManager.fillReport().

Two SQL query inside single JasperReport and populating Data

We are using reports in our web application.
The report is generated using JasperReports.
The problem I am facing is:
My SQL query fetches data based on a where clause:
SELECT * FROM table WHERE level='c'
I can easily show this information inside the iReport.
But I need to fire another query where level='d' and the information for the same needs to be appended to the report with that of level='c'.
I tried grouping both the outputs. But problem is how do I fire two different query while generating the report because I can write only one query in QueryBuilder inside the iReport.
Is there anyway of achieving the same.
In essence:
The report should look like:
Level=C
Name Age Phone number
Level=D
Name Age Phone number
Level D should appear only after level c is completed.
Can anyone please guide.
I finally managed to achieve the same..Grouping the data using level_id..
Initially I was trying to group in a different manner and hence the value was not getting shown..
The same is explained pretty nicely in ireport Ultimate guide-3 document.