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

问题描述 投票:3回答:1

我想将整个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);
    }
java sql jasper-reports
1个回答
2
投票

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

“在此处输入图像描述”

© www.soinside.com 2019 - 2024. All rights reserved.