2014-10-06 68 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); 
     }