I have this simple code:
JasperDesign jDes = JRXmlLoader.load("jasperfile.jrxml");
String sql = "Select * From table WHere address like 'St. Vincents College%'";
JRDesignQuery newQuery = new JRDesignQuery();
newQuery.setText(sql);
jDes.setQuery(newQuery);
JasperReport jRep = JasperCompileManager.compileReport(jDes);
JasperPrint jPrint = JasperFillManager.fillReport(jasperReport,null,conn);
JasperViewer.viewReport(jPrint);
so basically that print's the report. What I want is instead of SELECT... query, I want to use a stored procedure let's say:
ProcedureName: GenerateReportByAddress
Parameter : personName
How can I use CallableStatement in jasper?
CallableStatement cstmt = con.prepareCall("{call GenerateReportByAddress(?)}");
cstmt.setString(1, "secret");
Reasons are:
- to make query of application encapsulated by calling only stored procedure
- to avoid SQL Injection. (because some address contains Single Quote)
Jasper Reports does not support stored procedures. Temp tables is the right approach. For more details see this blog entry:
How To Call Stored Procedures From JasperReports
and alternatively, You can bind Jasper Reports to a different datasource. See here:
Java beans as Jasper Reports data source using JRBeanCollectionDataSource
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With