繁体   English   中英

在 jasper 报告中将整个 sql 查询作为参数传递

[英]Passing an entire sql query as a parameter in jasper reports

我想将整个 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);
    }

我在同事的帮助下找到了答案。 我不得不在 jasper 报告的 xml 文件(例如;report.jrxml)中将参数 ($P{QUERY}) 更改为 ($P!{QUERY})

在此处输入图片说明

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM