我想将整个sql查询作为参数传递给jasper报告。我尝试使用$ P {QUERY},但它给了我一个mysql语法错误异常。我希望它在运行时通过。有谁知道怎么做?
示例代码:
try {
Map<String, Object> map = new HashMap<>();
Connection conn = DatabaseConnection.getInstance().getConnection();
map.put("QUERY", "Select u.name, u.status from user_info u where u.user_name = 'Thanuj'");
JasperReport report = JasperCompileManager.compileReport("report1.jrxml");
JasperPrint jp = JasperFillManager.fillReport(report, map, conn);
JasperViewer.viewReport(jp, false);
} catch (JRException ex) {
Logger.getLogger(ReportTest.class.getName()).log(Level.SEVERE, null, ex);
} catch (SQLException ex) {
Logger.getLogger(ReportTest.class.getName()).log(Level.SEVERE, null, ex);
} catch (ClassNotFoundException ex) {
Logger.getLogger(ReportTest.class.getName()).log(Level.SEVERE, null, ex);
}
答案 0 :(得分:2)
我在同事的帮助下找到了答案。我必须在jasper报告的xml文件(ex; report.jrxml)中将参数($ P {QUERY})更改为($ P!{QUERY})