Jump to content
Changes to the Jaspersoft community edition download ×

Newbie:Help in using Jasper Reports


Recommended Posts

By: Finixf - finixf

Newbie:Help in using Jasper Reports

2006-03-20 06:04

Hi there,

 

I am new to Java as well as Jasper reports.

I am making a project in Sun Java Studio creator.

I want to implement report generation in my project.

I have heard of Jasper Reports.But I am not able to find out how to use Jasper reports.

I am unable to find the documentations for integrating Jasper Reports with java applications.

 

Can some body help??

 

Thanks

 

 

By: soujiro_as - soujiro_as

RE: Newbie:Help in using Jasper Reports

2006-03-21 14:40

Hi, in order to report generation, you want to use the package JasperReportsXX.jar.

 

I have downloaded the .zip file (the project, not only the jar), this have a folder named "lib" wich contains the libraries used by JR, I think that you need to copy these libraries to your project.

 

To create a report, you can create a xml (jrxml) file (read the tutorial in the JR website), and load like a file or like a stream (this is in a web app):

InputStream templateInputStream = request.getSession().getServletContext().getResourceAsStream("/reports/template.jrxml");

 

then, you need to load the template and create a jasperDesign:

 

jasperDesign=JRXmlLoader.load((InputStream)templateInputStream);

 

next, you need to add the parameters and compile the report:

 

setDesignParameters(jasperDesign,reportParams); JasperReport jreport=JasperCompileManager.compileReport(jasperDesign);

 

next, if all is ok, you need to fill the report, to this, JR uses a datasource (to execute the query), and the values of the params:

Connection conn=(Connection)dataSource;

jasperPrint =

JasperFillManager.fillReport(

jreport,

reportParams,

conn

);

Finally, if all is ok, you can export the report filled(jasperPrint) in the format you selected, i.e. in PDF:

 

JRAbstractExporter exporter=new JRPdfExporter();

exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);

exporter.exportReport();

 

And, this is all, this code is a summary(this don´t run as is) I remove the try/catch and other things, but the basic is here.

Hope that helps, Alvaro

 

 

By: soujiro_as - soujiro_as

RE: Newbie:Help in using Jasper Reports

2006-03-21 14:50

P.D.

The line: setDesignParameters(jasperDesign,reportParams);

Is a method that add's the params to my jasperDesign object, if you use the jrxml file to generate the report, you don´t need to add the parameters(I'm generating the report by means of the JR API).

 

 

By: Finixf - finixf

RE: Newbie:Help in using Jasper Reports

2006-03-29 21:05

Hi, soujiro_as

 

Thank you very much for your reply and suggestions.

Link to comment
Share on other sites

  • Replies 0
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Top Posters In This Topic

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...