Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / Tools / February 2004

Tip: Looking for answers? Try searching our database.

Jasperreports & iReport - question

Thread view: 
Kouroukidis Dimitrios - 28 Feb 2004 13:07 GMT
Hi,

 I'm using Jbuilder X. Recently I was sugested to use jasperreports
in order to create reports for my application which uses an ms access
db. I searched a little more and discovered iReports which is a
perfect GUI for designing reports.

 Now... within iReport I could creare my reports and see them running
in all formats (pdf, html, java etc etc etc), that is cool. BUT, what
about implementing the reports in my java application ?

 How do i do that ? How do I implement or integrate jasperreports in
jvbuilder so I can import the required classes and view-print reports
within my API... OR is there another way ? I'm afraid, the
documentation from jasperreports does not describe how to integrate
jasperreports with your development tool in order to implement in the
source code.

Please HELP.... I'm burning here... !!!

My e-mail is dimitr13@otenet.gr or bacaru@freemail.gr .

Thank is advance,

Dimitri Kouroukidis
steve - 28 Feb 2004 22:24 GMT
> Hi,
>
[quoted text clipped - 21 lines]
>
> Dimitri Kouroukidis

Is it so hard to read the example programs for this?
I
1. take your  iReport.xml file
2. run it thru the Jasper report library.

the following code sample will process a report file "report3x4.xml" ( no
this is not with the libraries you have to lay it out yourself, and is my
layout)

just do an IReport with a simple text field "hello world"

You will also need the Itext libraries to handle the pdf conversion.

HERE IS SOME SAMPLE CODE, THIS WORKS as it is extracted from a current
project.
It ensures the xml report is re-compiled each time.

Finally to get data from a database you must build a custom data source,
which runs to about 10 lines of java code. I'm already doing the same with
oracle.

  Map parameters = new HashMap();
//strings in the "" are the names of the jasper report fields.

       parameters.put("ReportTitle", Header[0]);
       parameters.put("FactoryName", Header[1]);

String PrintType="P.D.F";
//String PrintType="!P.D.F";

//this sets up the base footer
//note that the strings it the "", are the names of the fields on the jasper
//reports, for  this test you can strip out  the "  parameters" code.
//this sets up the base footer and pulls the stuff from an array
//setup some place else, the array contains Strings

       parameters.put("thspg", Footer[0]);
       parameters.put("pgcnt", Footer[1]);
       parameters.put("thsdate", Footer[2]);
       parameters.put("auth", Footer[3]);
       parameters.put("docidx", Footer[4]);
       parameters.put("repidx", Footer[5]);
       parameters.put("draft", Footer[6]);

       //this sets up the base footer
       parameters.put("thspgttl", FooterTitles[0]);
       parameters.put("pgcntttl", FooterTitles[1]);
       parameters.put("thsdatettl", FooterTitles[2]);
       parameters.put("authttl", FooterTitles[3]);
       parameters.put("docidxttl", FooterTitles[4]);
       parameters.put("repidxttl", FooterTitles[5]);
       parameters.put("draftttl", FooterTitles[6]);
       parameters.put("thspg", Footer[0]);
       parameters.put("pgcnt", Footer[1]);
       parameters.put("thsdate", Footer[2]);
       parameters.put("auth", Footer[3]);
       parameters.put("docidx", Footer[4]);
       parameters.put("repidx", Footer[5]);
       parameters.put("draft", Footer[6]);

       //this sets up the base footer
       parameters.put("thspgttl", FooterTitles[0]);
       parameters.put("pgcntttl", FooterTitles[1]);
       parameters.put("thsdatettl", FooterTitles[2]);
       parameters.put("authttl", FooterTitles[3]);
       parameters.put("docidxttl", FooterTitles[4]);
       parameters.put("repidxttl", FooterTitles[5]);
       parameters.put("draftttl", FooterTitles[6]);

       try {
           String RawfileName = "report3x4.xml";

//pre-compile the report, use default extension of "jasper"

           JasperCompileManager.compileReportToFile(RawfileName);

           String CompiledfileName = "report3x4.jasper";
           JasperFillManager.fillReportToFile(CompiledfileName, parameters,
               new CustomDataSource(data));

           String PsudocodefileName = "report3x4.jrprint";
           String finaloutputfileName = "Final_report.pdf";

           if (PrintType.equalsIgnoreCase("P.D.F")) {
               JasperExportManager.exportReportToPdfFile(PsudocodefileName,
                   finaloutputfileName);
           } else {
               //just print it out to the normal printer
               JasperPrintManager.printReport(PsudocodefileName, true);
           }
       } catch (JRException e) {
           Error_stuff.Error_funcs.handleError(e, -1, -1);
           e.printStackTrace();
       }
   }


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.