Jump to content

How can I add parameters Directly to the JDBC Statement in jasper reports


ahmad.kassyd

Recommended Posts

What I am trying to achieve is add a dynamically created criteria to the report query. The user designs the criteria using a GUI, she can add a list of ($field $operator $value) expressions.


What would be the best way to achieve this?


I do not want to change the report design by adding the new parameters and changing the query. What I need is to pass a parameter with the criteria; and then provide the positional parameters to the JDBC statement. Of course there is the problem of finding what are the indices of my parameters; but we will cross that bridge when we come to it.


Thanks


Link to comment
Share on other sites

  • Replies 2
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Top Posters In This Topic

Hi,

The most suitable method for this situation of your can be that,  for instance:

you can create parameters ($field $operator $value) and then you can fill these via GUI or a list which ever suits your cause.

Then you can create a single parameter , suppose $P{customCondition}, this will not be set by the user so the Prompt would be unchecked for this.

The default expression for this parameter will be $P{field}+$P{operator}+ $P{value} 

Now, use this prameter in the query in the where condition along with the AND $P!{customCondition} and that shall be all.

above is the most feasible method.

 

Thanks

 

 

Link to comment
Share on other sites

By "a list of ($field $operator $value) expressions" I mean that there are more than one expression for example "( x = "a" and y <=10) or z is null" and so on.

The second thing, values in expressions are not all strings, some are binary data, some are numbers, etc.

Also, your solution will make my reports vulnerable to sql injection.

Thanks a lot for your time.

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