我有这个简单的代码:
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);
所以基本上打印报告。我想要的是代替SELECT...
查询,我想使用存储过程让我们说:
ProcedureName: GenerateReportByAddress
Parameter : personName
如何在jasper中使用CallableStatement
?
CallableStatement cstmt = con.prepareCall("{call GenerateReportByAddress(?)}");
cstmt.setString(1, "secret");
原因是:
- to make query of application encapsulated by calling only stored procedure
- to avoid SQL Injection. (because some address contains Single Quote)
答案 0 :(得分:2)
Jasper Reports
不支持存储过程。临时表是正确的方法。有关更多详细信息,请参阅此博客条目:
How To Call Stored Procedures From JasperReports
或者,您可以将Jasper Reports
绑定到其他数据源。见这里:
Java beans as Jasper Reports data source using JRBeanCollectionDataSource