This week's book giveaway is in the Reactive Progamming forum.
We're giving away four copies of Reactive Streams in Java: Concurrency with RxJava, Reactor, and Akka Streams and have Adam Davis on-line!
See this thread for details.
Win a copy of Reactive Streams in Java: Concurrency with RxJava, Reactor, and Akka Streams this week in the Reactive Progamming forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Junilu Lacar
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Ganesh Patekar

simple jasper report in java without a database.

 
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
???
Any suggestions? Any ideas?

Best regards.
 
Ranch Hand
Posts: 133
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@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
Posts: 133
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@John

Yes. You are right. Issue is resolved. My .jasper was stroed at different location and I was using different one.
Thank you.
 
The harder you work, the luckier you get. This tiny ad brings luck - just not good luck or bad luck.
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!