java - Dynamic Query in Jasper Report -


I am using Jasper Reports with Java to create some reports in the interface, user select 1 or more items , And a report is prepared for each item. Now, I have a query:

  select stock exchanges   

This is in jrxml file. But, running through my app, it will prepare a report for each item in the table. What do I want: stock inventory WHERE pk IN (? ...)

Where "? ..." are selected by the user:

  SELECT * The keys of the item, therefore, not only the parameters are dynamic, but the number of parameters is also dynamic.  

My problem is, I do not know how to set up the parameters in jrxml and I do not know how to set the parameters from within the jasperreports library in java currently, to set the values ​​i do this I am:

  Maps & lt; String, Object & gt; Parameters = new Hashmop & lt; String, Object & gt; (); JasperReport Report = JasperCompileManager.compileReport ("path \\ from \\ jrxml"); JasperPrint Print = JasperFillManager.fillReport (Report, Parameter, New ItemData (Keys));   

where item is ():

  Private class madadata applies JRDataSource {Private Final List & lt; Inventory item & gt; item; Private int counter; Public item data (list & gt; primary key & gt; keys) {items = new arrelist & lt; Inventory item & gt; (); Inventory Itamdao Dao = New Inventory Itamdao (); (Primary key key: keys) {Inventory item item = Dao.Find (key.getPk (), key.getCpk ()); If (item! = Null) {items.add (item); }} Counter = -1; } @ Override Public Boolean throws JRException (if counter (lt; items.size) - 1) {counter ++; true;} description is false;} Override public object found value (JRFild JRF) Returns the xeroxation {// Return related fields}}   

The problem with this is that this looping is done through the primary key selected by the user, for each of them Query if I make it a single dynamic I can do it with a lot, so it will be very easy.

Thanks for any help!

To set parameters from Java, you must put them in your parameter object.

  Map & lt; string, object & gt; Params = New Hashmop & lt; String, Object & gt; (); params.put ("paramName", value); JasperReport Report = JasperCompileManager.compileReport ("Path \\ from \\ jrxml"); JasperPrint Print = JasperFillManager.fillReport (Report, Parameter, New ItemData (Key) X)); And then make sure to use it in reports like $ P {paramName}, when you declare the parameter in the report for the same name ('nickname'), and its class is in your  Value is the square of the object.  

If you wish to use these clauses, you must use the built-in SQL segment functions provided by Jasper.

Format $ X {IN, & lt; column_name & gt;, & lt; Parameter_name & gt;} (without $ P, in this case, be sure to use the name of the parameter).

Then, in your case, the query will be:

SELECT * Stock exchange from stock where $ X {IN, pk, paramName} The parameter 'paramName' can be either a java.util.Collection example or java.util.List example.

Comments

Popular posts from this blog

Verilog Error: output or inout port "Q" must be connected to a structural net expression -

jasper reports - How to center align barcode using jasperreports and barcode4j -

c# - ASP.NET MVC - Attaching an entity of type 'MODELNAME' failed because another entity of the same type already has the same primary key value -