So i did a little research and test by myself. There is a one trick to put sql query statement as a parameter in ireport. The purpose to do this is when you want to call the jasper report in your application is either client or the web, you can pass the specific query to your jasper report.
Here is the step:
- Create your report
- Use Static query for example like "Select * Fom Companies";
- Add your field to your report.
- Create one parameter let say "sql_input_param" as java.lang.String
- Set the default value same like step no 2.(just in case you forgot to pass the parameter, the default value will handle it.
HERE IS THE TRICK
- Modify your query to be $P!{sql_input_param} < -- as you can see, there is a exclamation symbol after letter P. Its is used to pass parameter as sql query in ireport query.
Now you can test to pass query statement as parameter in ireport
HashMap<String, Object> parameters = new HashMap<>();now you can pass the query statement as parameter in iReport.
var sql = "SELECT * FROM companies WHERE companies.company_id = " + forms.frm_company.company_id + " order by companies.company_id";
parameters .put('sql_input', sql);
Connection jdbcConnection;
JasperReport jasperReport;
JasperPrint jasperPrint;
JRPdfExporter exporter = new JRPdfExporter();
JasperDesign jasperDesign = JRXmlLoader.load(F);
jasperReport = JasperCompileManager.compileReport(jasperDesign);
jasperPrint = JasperFillManager.fillReport(jasperReport, param, jdbcConnection);
::
::
::
::
By Mohd Zulkamal
NOTE : – If You have Found this post Helpful, I will appreciate if you can Share it on Facebook, Twitter and Other Social Media Sites. Thanks =)
0 comments:
Post a Comment