Jasper报告与Java的集成

Jasper报告与Java的集成,java,jasper-reports,Java,Jasper Reports,尝试了下面的代码,但未生成PDF报告。刚从Jasper积分开始。请帮忙 public String mainReport() { HashMap jrxmlParams = null; try { System.out.println("Start ...."); // Get jasper report String jrxmlFileName = "C:/Jasper/DP_crosstabs.jrxml";

尝试了下面的代码,但未生成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());
    }

    }}
试试下面的代码

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

    }}

已经添加了所有相关jar文件,有人可以帮助这是一个桌面应用程序吗?已经添加了所有相关jar文件,有人可以帮助这是一个桌面应用程序吗?感谢您的帮助Sadagopan,它成功了:。。。但根据项目要求,我们必须以HTML格式生成报告。可以使用导出管理器创建文件,但无法在同一实例中查看相同的文件。请帮忙!!!Hi Jasper viewer将在同一实例中为所有格式触发生成的报告。。请将以上内容标记为答案。感谢你的帮助Sadagopan,成功了:。。。但根据项目要求,我们必须以HTML格式生成报告。可以使用导出管理器创建文件,但无法在同一实例中查看相同的文件。请帮忙!!!Hi Jasper viewer将在同一实例中为所有格式触发生成的报告。。请将以上内容标记为答案。谢谢