This week's book giveaway is in the OCPJP forum. We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line! See this thread for details.
I have an application that uses Jasper Reports to show contents from a table onto a PDF file. (basically a select * from some table with a where condition)
This is my problem. When the sql returns data the PDF is shows up correctly. The PDF is generated even when the database does not return any rows. A message stating "The file cannot be opened because it has no pages" is shown on the screen.
How do I avoid an empty report to be displayed. The byte array returned is not empty so the the report pops up the pdf.
When your query yields no results, there're 3 options that are provided by JR that you could make use of: (a) generate empty report (PDF), i.e., no pages (b) generate a single blank page report (c) generate a report showing all sections, except the detail section
This can be done by setting the value of the attribute [B}whenNoDataType[/B] for element jasperReport. The 3 accepted values are: (a) NoPages (b) BlankPage (c) AllSectionsNoDetail