Passing Parameters to SQL

Stimulsoft Reports.JAVA discussion
Loki87
Posts: 19
Joined: Thu Dec 10, 2015 1:17 pm

Passing Parameters to SQL

Post by Loki87 »

Hello Stimulsoft,

I am working on my own Report to Pdf exporter and I want to pass parameters with Java to get a query for my report, so the report can show me the data, my Select command are in php working with a Restful webservice.

Do I have to set something in the designer in the dictionary to pass the parameter to the sql command or do I pass the parameter directly to the sql command?

I have found this:

report.getDictionary().getVariables().get(var).setValue(val);
report.getVariables().put(var, val);

but I dont understand how to use it to pass parameters to sql.

Thank you

best regards

Loki
Vadim
Posts: 363
Joined: Tue Apr 23, 2013 11:23 am

Re: Passing Parameters to SQL

Post by Vadim »

Hello.
For example you can define Variable1 <int> & then your sql string may look like: select * from actor where actor_id = {Variable1}
Loki87
Posts: 19
Joined: Thu Dec 10, 2015 1:17 pm

Re: Passing Parameters to SQL

Post by Loki87 »

Hello.

If my sql string is looking like this:

"select* from actor where actor_id = @variable1"

and in Java I am getting the value of my jtextfield in the gui and use this code:

report.getDictionary().getVariables().get("@variable1").setValue(val);
report.getVariables().put("@variable1", val);

do I need to define this variable in the dictionary or can I pass the value directly from the code to the sql string???
Vadim
Posts: 363
Joined: Tue Apr 23, 2013 11:23 am

Re: Passing Parameters to SQL

Post by Vadim »

Hello.
You must use variables in {} not use @-symbol.
If you not define this variable in the dictionary you must put it by code, lilke:
report.getDictionary().getVariables().add(new StiVariable("variable1", 1));
Loki87
Posts: 19
Joined: Thu Dec 10, 2015 1:17 pm

Re: Passing Parameters to SQL

Post by Loki87 »

Hello,

is there a way in code to retrieve the path to the json data from the report object and change the path??
Vadim
Posts: 363
Joined: Tue Apr 23, 2013 11:23 am

Re: Passing Parameters to SQL

Post by Vadim »

Hello.
You can do like this:

Code: Select all

((StiJsonDatabase) report.getDictionary().getDatabases().get(0)).setPathData("/data.json");
Loki87
Posts: 19
Joined: Thu Dec 10, 2015 1:17 pm

Re: Passing Parameters to SQL

Post by Loki87 »

Hello.

Thank you, getPathData is working, with System.out.print I see the Path of my Json database, but it shows me a warning:

Feb 10, 2016 9:00:05 AM com.stimulsoft.report.engine.parser.StiParser ParseTextValue
WARNUNG: Parser error: The name '%s' does not exist in the current context, FHBill, , ,

and setPathData is not working, it shows me the same warning, do I have to do something with the dictionary or the dataSource after I set the Path??
Loki87
Posts: 19
Joined: Thu Dec 10, 2015 1:17 pm

Re: Passing Parameters to SQL

Post by Loki87 »

It's working now without the warning, and the setDataPath method is working, too.

Thank you.
HighAley
Posts: 8431
Joined: Wed Jun 08, 2011 7:40 am
Location: Stimulsoft Office

Re: Passing Parameters to SQL

Post by HighAley »

Hello.

Thank you for informing us about your issue.
We are always glad to help you.

Thank you.
smartleopard
Posts: 22
Joined: Wed Apr 01, 2015 2:29 pm

Re: Passing Parameters to SQL

Post by smartleopard »

Hi,

I've used the code below to add variable to dictionary:

report.getDictionary().getVariables().add(new StiVariable("variable1"));

but it adds category to flex designer and not a variable.
Post Reply