How to connect java swing app to jasper report? (frustrated java swing programmer)

Hi guys, can anybody point me in the right direction on how to connect a java swing app to a jasper report. This Jasper report is touting itself as a java enabled reporting tool yet there's not one single resource or tutorial about connecting to a goddamn java swing app to a report why is it so mysterious and hard to learn this tool? I am really frustrated after searching for days on end in the internet about a single tutorial about utilizing jasper reports in a java swing app and came out with nothing. Can somebody please give me some code or solid context on connecting a java swing app with a jasper report so I can generate my report from a mysql database? Any help will do and please be specific with the answers and please don't give mysterious  or general answers that don't answer a single thing. And which should I use ireport or studio? Should I make a .jrxml file first and then connect it with the java swing app? Somebody help please. Why is this so goddamn hard?

ml.francis's picture
Joined: Sep 2 2014 - 1:19am
Last seen: 2 years 9 months ago

1 Answer:

It isn't hard... I started also ~16 years ago from "a green field" and learned step by step with running the sample provided within the full JasperReportsProject zip that is also free for download.  The problem nowadays is - don't take it personally - that everbody just want to get full working code instead of developing it by yourself... so remember what "develop" means... not take ready src + compile + run + be happy... it's a process that takes time and is kind of learning by doing ... adapt ideas from other sample code to your own code, read the manual + forum entries... so this is much more efficient to understand how JasperReports is working ... so my personal opinion.

So perhaps in few steps :

  1. include your report designs (jrxml) in your swing-app-jar or load them dynamically from a file system folder (depends on how you want to deploy your app and if the designs should be changeable at runtime)
  2. load your designs with the JRLoader and compile them via the JRCompileManager to a so called JasperReport Object (tip: if the designs are fix, you could also load the .jasper files directly into a JasperReport Object without compiling the designs (*.jrxml))
  3. Fill the Report with the JRFillmanager by passing the filled parameters map and the prepared (my)sql-connection (so the connection object must be created before!) to the fill method. 
  4. You will get an (filled) JRPrintObject from the result of the fill process (or even an empty one, if the query inside doesn't returned results). So you could now open that filled JRPrint object with the built.in JRViewer or you could also export it to a PDF-file or whatever with the JRExportManager

so finally #5: don't give up - I know you wanted sample code... it's at home on my local pc and I think you will manage it also by viewing into the samples provided by JasperSoft also! 

hth + regards

C-Box

 

C-Box's picture
20525
Joined: Jul 19 2006 - 5:58pm
Last seen: 5 months 1 week ago
Feedback