Java Programming – Call jasper report from java

customize JasperViewer, change Title and other tool bar

Java Programming – Call jasper report from java

Hi friends,

I amusing jasper report for reporting my application. If I call .jrxml file the report successfully added in my application but .jasper file could not be loaded. I download some sample code from one website that code also not working. Please help me. This is the sample code.

import javax.swing.*;
import java.awt.*;
import java.sql.*;
import java.util.*;
import java.io.*;

import net.sf.jasperreports.engine.*;
import net.sf.jasperreports.engine.design.*;
import net.sf.jasperreports.view.*;

public class ReportViewer extends JFrame
{

public ReportViewer(String fileName)
{
this(fileName,null);
}

public ReportViewer(String fileName,HashMap parameter)
{
super(“View Report");
try
{

Class.forName(“sun.jdbc.odbc.JdbcOdbcDriver");
Connection con = DriverManager.getConnection(“jdbc:odbc:udtsteelshop");

JasperPrint print = JasperFillManager.fillReport(fileName, parameter, con);

JRViewer viewer=new JRViewer(print);

Container c=getContentPane();
c.add(viewer);
}
catch(ClassNotFoundException cnfe)
{
cnfe.printStackTrace();
}
catch(SQLException sqle)
{
sqle.printStackTrace();
}
catch(JRException jre)
{
jre.printStackTrace();
}

setBounds(10,10,600,500);
setDefaultCloseOperation(DISPOSE_ON_CLOSE);

}

public static void main(String args[])
{

HashMap param=new HashMap();
param.put(“FromDate", “2009-07-22″);
param.put(“ToDate", “2009-07-25″);
ReportViewer viewer=new ReportViewer(“C:\\Documents and Settings\\TAINNTECH\\My Documents\\NetBeansProjects\\UdtSteelShop\\Reports\\PurchaseList.jasper",param);
viewer.setVisible(true);
}
}

發表迴響

你的電子郵件位址並不會被公開。 必要欄位標記為 *

What is 7 + 12 ?
Please leave these two fields as-is:
IMPORTANT! To be able to proceed, you need to solve the following simple math (so we know that you are a human) :-)