使用jaseprreportts打印多个报告

时间:2014-10-06 14:34:45

标签: java jasper-reports

是否可以一次打印多份报告?

我目前使用以下代码打印报告

String report = "someReport.jasper";
Map<String,Object> hm = new HashMap<>();
hm.put("id", id);  // some id to fetch data from database

JasperPrint jprint;
try{
    jprint = (JasperPrint) JasperFillManager.fillReport(report, hm, MySQLConnection.getAppServerConnection());
    JasperViewer.viewReport(jprint,false);
} catch (JRException e) {
    e.printStackTrace();
}

我想用不同的参数(id)多次调用同一个报告,并在打印前在单个JasperViewer中显示

1 个答案:

答案 0 :(得分:0)

我是这样做的。

ResultSet rs = getRS(con); 

while (rs.next()) {

        Map<String,Object> parameters = new HashMap<String, Object>();
        parameters.put("Id", Id);
        parameters.put("XYZ", XYZ);

        try {
            JasperPrint jasperPrint = JasperFillManager.fillReport(pdfReport, parameters, con);
            JasperExportManager.exportReportToPdfFile(jasperPrint, OutputFolder + "\\" +         PdfFileName);
        }
        catch (Exception e) {
            System.out.println(getMessage());
        }

public ResultSet getRS(Connection con) throws SQLException {
       Statement stmt = null;
       String query = "Put your query here";
       try {
           stmt = con.createStatement();
           ResultSet rs = stmt.executeQuery(query);
           return rs;
       } catch (SQLException e ) {
        throw(e);
       }