[英]Jasper Report integration to Java
嘗試以下代碼,但未生成PDF報告。 剛開始使用Jasper整合。 請幫忙。
public String mainReport() {
HashMap jrxmlParams = null;
try {
System.out.println("Start ....");
// Get jasper report
String jrxmlFileName = "C:/Jasper/DP_crosstabs.jrxml";
JasperReport objJReport = JasperCompileManager.compileReport(jrxmlFileName);
connection = getConnection();
jrxmlParams = new HashMap();
jrxmlParams.put("ID", "null");
JasperPrint objJPrint = JasperFillManager.fillReport(objJReport, jrxmlParams, connection);
ByteArrayOutputStream objBAOutputStream = new ByteArrayOutputStream();
JasperExportManager.exportReportToPdfStream(objJPrint, objBAOutputStream);
System.out.println("Done exporting reports to pdf");
} catch (Exception e) {
System.out.print("Exceptiion" + e);
}
return null;
}
試試下面的代碼,
public static void main(String[] args) {
String reportPath = "/report3.jasper";
Map<String, Object> params = new HashMap<String, Object>();
Connection connection;
try {
Class.forName("com.mysql.jdbc.Driver");
connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/person","root","password");
System.out.println("Filling report...");
JasperPrint jasperPrint = JasperFillManager.fillReport(reportPath, params, connection);
JasperExportManager.exportReportToPdfFile(jasperPrint,
"/Test.pdf");
JasperViewer.viewReport(jasperPrint, false);
connection.close();
} catch (Exception e) {
System.out.println(e.getMessage());
}
}}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.