Jump to content
JasperReports Library 7.0 is now available ×

How to get String[] array Parameter


asper975

Recommended Posts

In IReport,I write a query below:

select * from student where name in ("smith","lisa","robert")

 

I want to use $P{name} replace ("smith","lisa","robert").

and the query change:

select * from student where name in ($P{name})

 

in java code outside:

String[] name={"smith","lisa","robert"}

parameters.put("name",name.toString());

myJPrint = JasperFillManager.fillReport(jasperReport, parameters, conn);

 

But it dosen't work. how to sovle this problem?

Link to comment
Share on other sites

  • Replies 4
  • Created
  • Last Reply

Top Posters In This Topic

You have to pass a string containing all your names:

 

Code:

String names = "'smith','lisa','robert'";

parameters.put("names",names);

myJPrint = JasperFillManager.fillReport(jasperReport, parameters, conn);

 

and to use a query like:

 

select * from student where name in ( $P!{names} )

 

Please note the exclamation mark before $P: in this way

names is not considered a query parameter, but a place order to replace with the content of that parameter.

The final query will be created by JR in this way"

 

"select * from student where name in (" +

"'smith','lisa','robert'" +

" )"

 

Giulio

Link to comment
Share on other sites

  • 2 years later...

 Can someone from JasperReports explain this little bit better ? There is no info about passing array as parameter in your Guide. I want to pass array of Strings, to select some data from database with in (as above), but I also want to define a condition on field or variable based on the input array parameter elements. How can I do this ? e.g., I want to say, if array contain 1, 2 I want to write 0 in my textfield.

 

--

Thx, Miki

Link to comment
Share on other sites

 No response to such a simple question :-(. Can PLEASE someone explain how to use array of Long's as Parameter in iReport ? I know that I can say select... in (var) in SQL, but how to pass such Parameter from program and how to define this variable in iReport ? 

And how can I use this array in field expression condition to check if such array contain some values ?

 

I read the book The Definitive Guide to iReport and some tutorials, but there is nothing about this!

--

Thx in advance, Miki

Link to comment
Share on other sites

  • 5 years later...

aswer

query:

from iv030 i,iv004 i4,iv008 i8
where i4.va_ide_alm=i.va_ide_alm and i4.va_nom_alm in ($P!{almacenes11})
and i.va_exi_can <> 0

CODE NETBENAS

String almacenes="'ALMACEN PROMOTORAS','ALMACEN OUTLET'";
             System.out.println("almacenes: "+almacenes);
            Map mapa=new HashMap();
             mapa.put("almacenes11", almacenes);

JasperPrint jp=JasperFillManager.fillReport(jr, mapa,con);
             JasperViewer.viewReport(jp);

 

 


 

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...