aspose file tools*
The moose likes Other Open Source Projects and the fly likes simple jasper report in java without a database. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Products » Other Open Source Projects
Bookmark "simple jasper report in java without a database." Watch "simple jasper report in java without a database." New topic
Author

simple jasper report in java without a database.

Rajubhai Kotwal
Ranch Hand

Joined: Nov 03, 2009
Posts: 47
Dear all,



I hope you are doing good. I would like to know whether we can generate a jasper report in java without using any database connection. I know we can generate jasper report in java with database connection. I have generated few reprts in .pdf and .xls format. Now I want to display some text on the the jasper report in java without database, say "hello jasper". I am using ireport. I have creaated a file and in that file, I have added a title in the title section $P{Report_title} . Now in the program, i am declaring a hashmap and trying put value in the hasmap like, hm.put("Report_title","Hello Report");

Later I am declaring JasperPrint like as follows.

JasperPrint print=JasperFillManager.fillReportToFile(fileName, outFileNamePDF, hm);

Here I am having problem about type mismatch:cannot convert from void to JasperPrint. I am not fully familiar with JasperReport API. I am trying to learn it with some simple examples first.In order to get the data on the report what I am supposed to do? Passing value from hashmap? Or shall use any collections? I would appreciate your suggestions. Thanks in advance. Please find the code. It's vary simple at the moment.



Best regards,

Rajubhai Kotwal
Ranch Hand

Joined: Nov 03, 2009
Posts: 47
???
Any suggestions? Any ideas?

Best regards.
John Bengler
Ranch Hand

Joined: Feb 12, 2009
Posts: 133
Hi Abhijit,

yes, you can create Jasper Reports without any database...

You can pass an XML or even a Java Map (or array) holding your datasource to the report..
(I think the report's datasource is your problem?)

You can download the samples here (see the link: "Download all Sample Source Files" or "Browse Sample Source Files on SVN" if you want just some of the samples):

Jasper Reports - Data Source Samples

If you downloaded the full zip-File you can find the samples under ...\jasperreports-3.7.1\demo\samples. For a demonstration on how to use non-DB-datasources especially the examples in the subfolders csvdatasource, datasource and xmldatasource may be helpful.

When I started using Jasper I used the XMLDatasource because you can easily play with your data and see the effect on the output..


Hope this is what you're looking for..

John

Rajubhai Kotwal
Ranch Hand

Joined: Nov 03, 2009
Posts: 47
@John Bengler

Than you very much for the reply and for the informative link. Well, I was able to find solution. I put

hm.put("Modified_status_code", "1");
JasperPrint print1=JasperFillManager.fillReport(fileName, hm, new JREmptyDataSource());

JREmptyDataSource could be the possible simple solution. Now I am thinking to go even deeper. I wish to put values (data) on the report at run time.
What I mean to say is, I do have a database and connectivity. Now I want to put values dynamically. Therefore, I am doing similar thing. I am not able to add the value anymore. I am writing here my code. Please let me know if you know anything. Suggestions are welcome.



I am getting error.
net.sf.jasperreports.engine.JRException: Unknown column name : Modified_status_code
This is the column name I am trying to add. Please note, now I am using Databse connectivity.

Best regard.

Best regards.
John Bengler
Ranch Hand

Joined: Feb 12, 2009
Posts: 133
Hi Abhijit,

you're welcome!

I think this time your problem doesn't have to do with your java code, but either with your report template or with your database...

Can you add your template?


John
Rajubhai Kotwal
Ranch Hand

Joined: Nov 03, 2009
Posts: 47
@John

Yes. You are right. Issue is resolved. My .jasper was stroed at different location and I was using different one.
Thank you.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: simple jasper report in java without a database.