This week's book giveaway is in the OCAJP 8 forum.
We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line!
See this thread for details.
The moose likes Other Open Source Projects and the fly likes how to generate dynamic reports in java Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of OCA Java SE 8 Programmer I Study Guide this week in the OCAJP 8 forum!
JavaRanch » Java Forums » Products » Other Open Source Projects
Bookmark "how to generate dynamic reports in java" Watch "how to generate dynamic reports in java" New topic

how to generate dynamic reports in java

sshruti dere

Joined: Sep 20, 2011
Posts: 6
How to generate dynamic reports using netbeans for a website?
I have display the data in my database in the form of piecharts and bar graphs?
M using postgres database and struts framework...
Please help...
Louis Bros
Ranch Hand

Joined: Jun 03, 2011
Posts: 54

You could create dynamic graphs with HTML5 Canvas using the data from your database.

Gaurav Sainii

Joined: May 18, 2009
Posts: 24
You can also try jasper java reporting API.
sshruti dere

Joined: Sep 20, 2011
Posts: 6
Thank you so much...
Can you please explain me indetail... what exactly should i do...
Because I have downloaded plugin for ireports and jasperreports...
But I dont know exactly how to use it...
Please reply...
Mr sujeet khandelwal

Joined: Dec 21, 2011
Posts: 13
Use this link it will be very helpful for you..

Servlet code for jasperreports:

import java.util.HashMap;
import java.util.Map;
import java.sql.*;
import javax.servlet.ServletException;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import net.sf.jasperreports.engine.*;
import net.sf.jasperreports.engine.xml.JRXmlLoader;
import net.sf.jasperreports.engine.export.*;

public class JasperReportServlet extends HttpServlet
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
ServletOutputStream servletOutputStream = response.getOutputStream();
Connection conn = null;
JasperReport jasperReport;
JasperPrint jasperPrint;
JasperDesign jasperDesign;
// get a database connection
conn = DriverManager.getConnection
("jdbc: oracle:thin:@ oracledb", "xyz","abc");

// create a map of parameters to pass to the report.
Map parameters = new HashMap();
parameters.put("Report_Title", "Salesman Details");

// load JasperDesign from XML and compile it into JasperReport
jasperDesign = JRXmlLoader.load("C:/jasperReports/demo.jrxml");
jasperReport = JasperCompileManager.compileReport(jasperDesign);

// fill JasperPrint using fillReport() method
jasperPrint = JasperFillManager.fillReport(jasperReport,parameters,conn);

//for creating report in excel format
JRXlsExporter exporterXls = new JRXlsExporter();
exporterXls.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
JasperExportManager.exportReportToPdfStream(jasperPrint, servletOutputStream);

catch(SQLException sqle)
catch (ClassNotFoundException e)
System.err.println("No such class found!");
catch (JRException e)
// display stack trace in the browser
StringWriter stringWriter = new StringWriter();
PrintWriter printWriter = new PrintWriter(stringWriter);
//close the connection.
if(conn != null)
try { conn.close(); }
catch (Exception ignored) {}

Nitin Surana
Ranch Hand

Joined: Jan 21, 2011
Posts: 129

Here is a working example of jasper reports on java servlets.
I agree. Here's the link:
subject: how to generate dynamic reports in java
It's not a secret anymore!