Switch to full style
General Java code examples
Post a reply

Jasper Report Java Usage Example

Fri Feb 01, 2013 12:26 am

Jasper Report example for library and print it to HTML.
java code
package ReportGen;

import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.Connection;
import java.util.HashMap;
import java.util.Map;
import javax.swing.JButton;
import javax.swing.JFrame;
import net.sf.jasperreports.engine.JRException;
import net.sf.jasperreports.engine.JasperCompileManager;
import net.sf.jasperreports.engine.JasperExportManager;
import net.sf.jasperreports.engine.JasperFillManager;
import net.sf.jasperreports.engine.JasperPrint;
import net.sf.jasperreports.engine.JasperReport;
import net.sf.jasperreports.view.JasperViewer;

/**
*
* @author sami
*/


/**
*
* @author user
*/
public class ReportPanel extends JFrame {

/** Creates a new instance of BorrowBookPanel */
public ReportPanel(Connection connection,JFrame myMother)
{

setTitle("Reports");
myconn=connection;

setSize(500,500);



cancel.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {

dispose();
}
});
BBew.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {

BorrBReport();
}
}); BS.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {

BookSReport();
}
});
Me.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
MemberReport();

}
});
setLayout(new FlowLayout());

add(BBew);
add(BS);
add(Me);
add(cancel);

}

public void BorrBReport()
{
String reportSource = "./reports/BorrowedBooks.jrxml";
String reportDest = "./reports/BorrowedBooks.html";

Map<String, Object> params = new HashMap<String, Object>();

params.put("reportTitle", "Borrowed Books");
params.put("author", "Casper");
params.put("startDate", (new java.util.Date()).toString());
try
{
JasperReport jasperReport =
JasperCompileManager.compileReport(reportSource);

// Make the driver class available.

JasperPrint jasperPrint =
JasperFillManager.fillReport(
jasperReport, params, myconn);

JasperExportManager.exportReportToHtmlFile(
jasperPrint, reportDest);

JasperViewer.viewReport(jasperPrint);
}
catch (JRException ex)
{
ex.printStackTrace();
}
}
public void MemberReport()
{
String reportSource = "./reports/Member.jrxml";
String reportDest = "./reports/Member.html";

Map<String, Object> params = new HashMap<String, Object>();

params.put("reportTitle", "Members");
params.put("author", "Casper");
params.put("startDate", (new java.util.Date()).toString());
try
{
JasperReport jasperReport =
JasperCompileManager.compileReport(reportSource);

// Make the driver class available.

JasperPrint jasperPrint =
JasperFillManager.fillReport(
jasperReport, params, myconn);

JasperExportManager.exportReportToHtmlFile(
jasperPrint, reportDest);

JasperViewer.viewReport(jasperPrint);
}

catch (JRException ex)
{
ex.printStackTrace();
}
}

public void BookSReport()
{
String reportSource = "./reports/BookStore.jrxml";
String reportDest = "./reports/BookStore.html";

Map<String, Object> params = new HashMap<String, Object>();

params.put("reportTitle", "Book Store");
params.put("author", "Casper");
params.put("startDate", (new java.util.Date()).toString());
try
{
JasperReport jasperReport =
JasperCompileManager.compileReport(reportSource);

// Make the driver class available.

JasperPrint jasperPrint =
JasperFillManager.fillReport(
jasperReport, params, myconn);

JasperExportManager.exportReportToHtmlFile(
jasperPrint, reportDest);

JasperViewer.viewReport(jasperPrint);
}

catch (JRException ex)
{
ex.printStackTrace();
}
}

private JButton BBew=new JButton("Borrowed Book");
private JButton BS=new JButton("Book Store");
private JButton Me=new JButton("Members ");

private JButton cancel=new JButton("Cancel");
private Connection myconn;


}


Used in :
finished-projects/library-database-management-system-project-t10813.html



Post a reply
  Related Posts  to : Jasper Report Java Usage Example
 Jasper report     -  
 Need Java program for display the CPU usage     -  
 crystal report     -  
 Crystal report     -  
 About Report Generation     -  
 How make a report using IReport on JSP?     -  
 dynamic crystal report generation     -  
 Can anybody give me a sample project report on mathematics f     -  
 Crystal report export to excel, page header issue asp.net     -  
 Usage of ins tag     -  

Topic Tags

Java Reports