Sai*_*nik 1 java jasper-reports
尝试下面的代码,但不生成PDF报告.刚开始使用Jasper integartion.请帮忙.
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;
}
Run Code Online (Sandbox Code Playgroud)
试试下面的代码,
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());
}
}}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2571 次 |
| 最近记录: |