Jasper Report - no datasource

For those who got the Open Source fever, sharing only makes you hot!

Moderator: neilg

Jasper Report - no datasource

Postby neilg » Fri Sep 02, 2005 12:33 am

This codesnippet shows how simple it is to print a jasper report. It has no data source and takes parameters from a HashMap. Jasper 0.6.7.

It is not a standalone working piece of code but it should show how simple it is to integrate JasperReports

Code: Select all
public void run()
   {
      JasperReport jr;
      JasperPrint prt=null;
      JREmptyDataSource empty;
      //
      if (inputStream==null)
      {
         throw new ReportException("The report stream cannot be null");
      }
      try {
         jr=(JasperReport)JRLoader.loadObject(inputStream);
         empty=new JREmptyDataSource();
         prt=JasperFillManager.fillReport(jr, map, empty);
         if (printPreview)
         {
            JasperViewer.viewReport(prt);
         } else
         {
            JasperPrintManager.printReport(prt, printDialog);
         }
         //
      } catch (Exception e) {
         e.printStackTrace();
         throw new ReportException(e);
      }
   }
[/code]
neilg
Regular
 
Posts: 141
Joined: Thu Jun 16, 2005 1:58 pm

Postby pshen » Sun Sep 04, 2005 11:56 pm

Yes, just missed one step-compile :)

Code: Select all
System.setProperty(
         "jasper.reports.compile.class.path",
         "lib/jasperreports-0.6.8.jar"
         );
   
System.setProperty(
         "jasper.reports.compile.temp",
         "/reports/"         );

try
{
    JasperCompileManager.compileReportToFile("/reports/Test.jrxml");
}
catch (JRException e)
{
         
    return;
}
pshen
 
Posts: 12
Joined: Thu Sep 30, 2004 5:58 pm
Location: China


Return to Contributor's Corner

Who is online

Users browsing this forum: No registered users and 1 guest

cron