Page 1 of 2
Passing Parameters to SQL
Posted: Thu Feb 04, 2016 9:43 am
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
Re: Passing Parameters to SQL
Posted: Thu Feb 04, 2016 12:18 pm
by Vadim
Hello.
For example you can define Variable1 <int> & then your sql string may look like: select * from actor where actor_id = {Variable1}
Re: Passing Parameters to SQL
Posted: Thu Feb 04, 2016 1:48 pm
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???
Re: Passing Parameters to SQL
Posted: Fri Feb 05, 2016 10:18 am
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));
Re: Passing Parameters to SQL
Posted: Tue Feb 09, 2016 8:27 am
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??
Re: Passing Parameters to SQL
Posted: Wed Feb 10, 2016 5:57 am
by Vadim
Hello.
You can do like this:
Code: Select all
((StiJsonDatabase) report.getDictionary().getDatabases().get(0)).setPathData("/data.json");
Re: Passing Parameters to SQL
Posted: Wed Feb 10, 2016 8:32 am
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??
Re: Passing Parameters to SQL
Posted: Wed Feb 10, 2016 9:16 am
by Loki87
It's working now without the warning, and the setDataPath method is working, too.
Thank you.
Re: Passing Parameters to SQL
Posted: Thu Feb 11, 2016 6:12 am
by HighAley
Hello.
Thank you for informing us about your issue.
We are always glad to help you.
Thank you.
Re: Passing Parameters to SQL
Posted: Wed Apr 27, 2016 4:51 pm
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.