Jump to content
We've recently updated our Privacy Statement, available here ×

passing variable as an array


umair

Recommended Posts

Hello!

Is there a possibility to pass multiple values to ireport as in a single variable?

I can see, that like other variables, i would declare an array variable.

But how would i parse the values to work with SQL query?

Link to comment
Share on other sites

  • Replies 6
  • Created
  • Last Reply

Top Posters In This Topic

okey...

so while passing these list of values through jasper server, the ireport is giving me classCastException.

the receiving parameter has a type String.

 

I know that i need to declare that 'string' parameter as an 'object' in ireport. (for handling of array string)

But now, i am kinda stuck...

what and how should i go about now ??

 

1. How should i use this value as in a query?

Link to comment
Share on other sites

hi umair

 

While passing values to the string parameter declared, use comma separated values and check the parameter as stated below:

 

 

normally we will check the parameter like this:

Code:
where report_id = $P{p_reportID}

 

 

where as in our case, we'll check like this:

Code:
[code]where report_id in $P{p_reportID}

 

 

DNV Srikanth

Link to comment
Share on other sites

hey DNV,

Thanx for the quick reply.

I tried what you suggested and i am facing the following exceptions:

 

Code:
java.sql.SQLException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '_binary'¬ísr1org.apache.commons.collections.set.ListOrderedSetüÓžöúíSL' at line 20

java.sql.SQLException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '_binary'¬ísr1org.apache.commons.collections.set.ListOrderedSetüÓžöúíSL' at line 20
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2928)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1571)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1666)
Link to comment
Share on other sites

So, i tried again with changing of paramteres and i observed that if a Collection's object e.g:

[1,2,3]

 

is being passed to the report, then the following expression

 

Code:
where report_id in ($P{p_reportID})

 

would evaluate to :

 

Code:
[code] where report_id in (1,2,3)

 

This would give an error.

 

So, i made two variables,

One p_reportID as a java.util.Collections and

str_p_reportID as java.lang.String

 

Now, str_p_reportID has a default expression of

 

org.apache.commons.lang.StringUtils.join($P{p_reportID}.toArray(),',')

 

I then use str_p_reportID in the query as:

 

Code:
[code]where report_id in $P{str_p_reportID}

 

This was supposed to return ("1","2","3")

but it now returns ("1,2,3").

 

I am kinda stuck ova here...

Post edited by: umair, at: 2008/05/07 14:52

Link to comment
Share on other sites

hi umair

 

So, i tried again with changing of paramteres and i observed that if a Collection's object e.g:

[1,2,3]

 

 

Instead of passing [1,2,3] which has square brackets pass comma seperated values to a string like this 1,2,3

 

 

It will work....

 

 

DNV Srikanth.

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