2014-10-06 90 views
0

是否可以在一批中打印多个报告?用jaseprreportts打印多个报告

我目前与下面的代码

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)同一份报告中多次调用,并打印

回答

0

这里之前在单JasperViewer显示它是如何我已经做了。

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); 
     }