RSS

New to JasperReport : Build your first impressive application (part 1)

27 Feb

I’ve made a previous article about setting up your environment to be a “JasperReport-ready”. You can click here to recall it.

And now, in this article, i will guide you to build your first JasperReport application. For this part, i will split this tutorial into 2 parts.

1. Let’s setup a dummy database. I’m using MySQL 5.0. Suppose we have a database named db_jasper

CREATE TABLE employees (
    employee_id VARCHAR(6) NOT NULL PRIMARY KEY,
    employee_name VARCHAR(30),
    salary INT(6)
);

INSERT INTO employees VALUES ('E0001','Hans Kristanto',5000000);
INSERT INTO employees VALUES ('E0002','Conrad Alvin',3500000);
INSERT INTO employees VALUES ('E0003','Luna Hu',4500000);
INSERT INTO employees VALUES ('E0004','Jina Seo',3650000);
INSERT INTO employees VALUES ('E0005','Ivan Lu',4510000);
INSERT INTO employees VALUES ('E0006','Dennis Ewing',500000);

2. Start your iReport designer.

iReport designer main window

3. Create a new report template
Click on File -> New, then choose any template paper. For example, Blank A4 (in iReport 3.7.0). For iReport 3.7.0 below, just follow the wizard as usual.
NOTES : For a while, never use Report Wizard! You have to do it manually.
Give it name and directory to be saved. Click on finish.

New Report

4. After that, you will see window like this

Report Designer

If you to the report designer, there are 7 sections. I will explain it one by one :

  • Title : is section for placing title document. Title document will only appear on the first page of document.
  • Page Header : is section for placing page header, for example, page number, title, etc. This header will appear in every page of report but not in the first page.
  • Column Header : is section for placing column header for detail title, for example, Employee Name, Salary. You will see the different in the real application.
  • Details : is section where you place all data. Detail section will iterate as much as fetched data. Again, you will see how it works in the real application.
  • Column Footer : similar with Column Header, but placed in the foot.
  • Page Footer : similar with Page Header, but placed in the foot.
  • Summary : is section where you put all summarize. For example, summary of total employees, total profits/loss, etc.

You have to understand these 7 sections first before we continue to the next step. Already understand? let’s go ahead!

5. Create a datasource
in the toolbar, you will see an database icon with a plug in front of it. . You will see a new window appear :

Click on New button on the right side, then follow the wizard. My suggestion :
– use Database JDBC Connection.
– give it name afterward.
– use com.mysql.jdbc.Driver as the JDBC Driver.
– type your database name on JDBC URL e.g. : jdbc:mysql://localhost/db_jasper
– type your username and password.

After that, you will see the drop down next to the database icon will be set into our new datasource :

New DataSource

Everything is done for setting up. Let’s continue for the next core tutorial on the part 2.

 
56 Comments

Posted by on February 27, 2010 in English, Programming

 

Tags: , , , , , , , ,

56 responses to “New to JasperReport : Build your first impressive application (part 1)

  1. diablo13

    February 27, 2010 at 11:09 pm

    Still waiting for part 2 impressive application😀

    Oya, in the next chapter (part) please give an example and simple code in Java. So that my desktop application for example, can use and call these jasperReport and print it appropriate to designing report that has been build in iReport.

    regards.

     
  2. Game

    April 2, 2010 at 9:33 pm

    Thanks for the informative post, found it really useful. ref And now, in this article, i will guide you to build your first JasperReport application. For this part, i will split this tutorial into 2 parts.

     
  3. Preludz

    June 3, 2010 at 4:35 pm

    Hi,

    Nice tutorial but I’ve a question.

    You wrote : “Page Header : is section for placing page header, for example, page number, title, etc. This header will appear in every page of report but not in the first page.”

    In fact, the page header do appear on the forst page, do you know why and how it is possible to not display it on the forst page ?

    Thanks

     
  4. Hans Kristanto

    June 3, 2010 at 8:07 pm

    Hi Preludz,

    i think i’ve made a mistake in writing detail about page header section since it will always shown in every report page. i’ve made some investigation about this and i still didn’t find the way to disable the first page header. i think it’s quite make sense enough since page header is an information needed to be printed in every page such as the day you print the report and so on. I really apologize about this mistake and i will repair it soon.

    Regards

     
  5. Preludz

    June 3, 2010 at 8:29 pm

    Hans,

    I found a way to resolve my problem by editing the report properties with the option : “Title on a new page”.

    Thanks a lot,

    Regards

     
  6. veja

    January 24, 2011 at 1:57 pm

    Hi
    I have a column header that is showing on page two even when data is only showing for page one. Can you please help to control a column header to only show only if there’s data ,on a second page. Thanks

    Regards

     
  7. Hans Kristanto

    January 24, 2011 at 4:33 pm

    Based on my experience, the things that you need to modify is in the layout, which means if you have only 1 page data but it showed 2 pages, means that there are whitespaces in your layout. i don’t know wether we can control page directly from code.

     
  8. sunjavastar

    October 18, 2011 at 2:38 pm

    can u explain how to use sub reports in jasper

     
  9. Hans Kristanto

    October 18, 2011 at 5:16 pm

    Theoritically using sub report in Jasper is linking 1 parent report with 1 child report tied with 1 or more parameters. you can configure it directly through iReport UI..so actually if you use sub report, you have to prepare at least 2 reports with 1 report act as a parent, and the other one act as a child.. after you merge it, it will be 1 single .jasper file.

     
  10. sunjavastar

    October 18, 2011 at 8:17 pm

    How to use collection like (arraylist) as sub report in jasper report using java code

     
  11. ashit

    February 9, 2012 at 7:04 pm

    Thanks

     
  12. Abdur Rahim

    February 24, 2012 at 1:10 pm

    Sir i have some problem to find out the cause for which my taskReport.jasper is not run from my java code although it’s run fine with i report
    my .jrxml file is as follows

    I use mysql as database and then compile it through ireport and produce a .jasper file and when i call it from my java code then it produce following error

    Exception in thread “AWT-EventQueue-0” java.lang.NoClassDefFoundError: org/codehaus/groovy/control/CompilationFailedException
    at java.lang.Class.getDeclaredConstructors0(Native Method)
    at java.lang.Class.privateGetDeclaredConstructors(Class.java:2389)
    at java.lang.Class.getConstructor0(Class.java:2699)
    at java.lang.Class.newInstance0(Class.java:326)
    at java.lang.Class.newInstance(Class.java:308)
    at net.sf.jasperreports.engine.JasperCompileManager.getCompiler(JasperCompileManager.java:469)
    at net.sf.jasperreports.engine.JasperCompileManager.loadEvaluator(JasperCompileManager.java:235)
    at net.sf.jasperreports.engine.fill.JRFillDataset.createCalculator(JRFillDataset.java:428)
    at net.sf.jasperreports.engine.fill.JRBaseFiller.(JRBaseFiller.java:430)
    at net.sf.jasperreports.engine.fill.JRVerticalFiller.(JRVerticalFiller.java:78)
    at net.sf.jasperreports.engine.fill.JRVerticalFiller.(JRVerticalFiller.java:88)
    at net.sf.jasperreports.engine.fill.JRVerticalFiller.(JRVerticalFiller.java:58)
    at net.sf.jasperreports.engine.fill.JRFiller.createFiller(JRFiller.java:142)
    at net.sf.jasperreports.engine.fill.JRFiller.fillReport(JRFiller.java:52)
    at net.sf.jasperreports.engine.JasperFillManager.fillReport(JasperFillManager.java:417)
    at net.sf.jasperreports.engine.JasperFillManager.fillReport(JasperFillManager.java:378)
    at Report.createReport.importParameter(createReport.java:124)
    at Report.createReport$1.actionPerformed(createReport.java:105)
    at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1995)
    at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2318)
    at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:387)
    at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:242)
    at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:236)
    at java.awt.Component.processMouseEvent(Component.java:6038)
    at javax.swing.JComponent.processMouseEvent(JComponent.java:3260)
    at java.awt.Component.processEvent(Component.java:5803)
    at java.awt.Container.processEvent(Container.java:2058)
    at java.awt.Component.dispatchEventImpl(Component.java:4410)
    at java.awt.Container.dispatchEventImpl(Container.java:2116)
    at java.awt.Component.dispatchEvent(Component.java:4240)
    at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4322)
    at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3986)
    at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3916)
    at java.awt.Container.dispatchEventImpl(Container.java:2102)
    at java.awt.Window.dispatchEventImpl(Window.java:2429)
    at java.awt.Component.dispatchEvent(Component.java:4240)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:273)
    at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:183)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:173)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:168)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:160)
    at java.awt.EventDispatchThread.run(EventDispatchThread.java:121)

    My java code is as follows

    public myReport {
    public static void main(String s[]){
    java.util.Date SDate=new Date(“01/01/2012”);
    java.util.Date EDateF=new Date(“020/02/2012″);HashMap map = new HashMap();
    JasperPrint jasperPrint = null;
    Connection connection = null;
    String s=”%”;
    try {
    Class.forName(“com.mysql.jdbc.Driver”).newInstance();
    connection== DriverManager.getConnection(“jdbc:mysql://localhost/task”, “root”, “”);
    map.put(“StartDate”, start);
    map.put(“EndDate”, end);
    map.put(“Id”,s);
    InputStream is = this.getClass().getClassLoader().getResourceAsStream(“Report/file/taskReport.jasper”);
    System.out.println(path);
    jasperPrint = JasperFillManager.fillReport(is, null, connection);
    JRViewer jv = new JRViewer(jasperPrint);
    JFrame jf = new JFrame();
    jf.getContentPane().add(jv);
    jf.validate();
    jf.setVisible(true);
    jf.setSize(new Dimension(800,600));
    jf.setLocation(300,100);
    jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    } catch (JRException ex) {
    System.out.println(ex.getMessage());

    }
    }
    }

     
  13. Abdur Rahim

    February 24, 2012 at 1:13 pm

    Sir i have some problem to find out the cause for which my taskReport.jasper is not run from my java code although it’s run fine with i report
    my .jrxml file is as follows

    I use mysql as database and then compile it through ireport and produce a .jasper file and when i call it from my java code then it produce following error

    Exception in thread “AWT-EventQueue-0″ java.lang.NoClassDefFoundError: org/codehaus/groovy/control/CompilationFailedException
    at java.lang.Class.getDeclaredConstructors0(Native Method)
    at java.lang.Class.privateGetDeclaredConstructors(Class.java:2389)
    at java.lang.Class.getConstructor0(Class.java:2699)
    at java.lang.Class.newInstance0(Class.java:326)
    at java.lang.Class.newInstance(Class.java:308)
    at net.sf.jasperreports.engine.JasperCompileManager.getCompiler(JasperCompileManager.java:469)
    at net.sf.jasperreports.engine.JasperCompileManager.loadEvaluator(JasperCompileManager.java:235)
    at net.sf.jasperreports.engine.fill.JRFillDataset.createCalculator(JRFillDataset.java:428)
    at net.sf.jasperreports.engine.fill.JRBaseFiller.(JRBaseFiller.java:430)
    at net.sf.jasperreports.engine.fill.JRVerticalFiller.(JRVerticalFiller.java:78)
    at net.sf.jasperreports.engine.fill.JRVerticalFiller.(JRVerticalFiller.java:88)
    at net.sf.jasperreports.engine.fill.JRVerticalFiller.(JRVerticalFiller.java:58)
    at net.sf.jasperreports.engine.fill.JRFiller.createFiller(JRFiller.java:142)
    at net.sf.jasperreports.engine.fill.JRFiller.fillReport(JRFiller.java:52)
    at net.sf.jasperreports.engine.JasperFillManager.fillReport(JasperFillManager.java:417)
    at net.sf.jasperreports.engine.JasperFillManager.fillReport(JasperFillManager.java:378)
    at Report.createReport.importParameter(createReport.java:124)
    at Report.createReport$1.actionPerformed(createReport.java:105)
    at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1995)
    at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2318)
    at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:387)
    at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:242)
    at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:236)
    at java.awt.Component.processMouseEvent(Component.java:6038)
    at javax.swing.JComponent.processMouseEvent(JComponent.java:3260)
    at java.awt.Component.processEvent(Component.java:5803)
    at java.awt.Container.processEvent(Container.java:2058)
    at java.awt.Component.dispatchEventImpl(Component.java:4410)
    at java.awt.Container.dispatchEventImpl(Container.java:2116)
    at java.awt.Component.dispatchEvent(Component.java:4240)
    at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4322)
    at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3986)
    at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3916)
    at java.awt.Container.dispatchEventImpl(Container.java:2102)
    at java.awt.Window.dispatchEventImpl(Window.java:2429)
    at java.awt.Component.dispatchEvent(Component.java:4240)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:273)
    at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:183)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:173)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:168)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:160)
    at java.awt.EventDispatchThread.run(EventDispatchThread.java:121)

    My java code is as follows

    public myReport {
    public static void main(String s[]){
    java.util.Date SDate=new Date(“01/01/2012″);
    java.util.Date EDateF=new Date(“020/02/2012″);HashMap map = new HashMap();
    JasperPrint jasperPrint = null;
    Connection connection = null;
    String s=”%”;
    try {
    Class.forName(“com.mysql.jdbc.Driver”).newInstance();
    connection== DriverManager.getConnection(“jdbc:mysql://localhost/task”, “root”, “”);
    map.put(“StartDate”, start);
    map.put(“EndDate”, end);
    map.put(“Id”,s);
    InputStream is = this.getClass().getClassLoader().getResourceAsStream(“Report/file/taskReport.jasper”);
    System.out.println(path);
    jasperPrint = JasperFillManager.fillReport(is, null, connection);
    JRViewer jv = new JRViewer(jasperPrint);
    JFrame jf = new JFrame();
    jf.getContentPane().add(jv);
    jf.validate();
    jf.setVisible(true);
    jf.setSize(new Dimension(800,600));
    jf.setLocation(300,100);
    jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    } catch (JRException ex) {
    System.out.println(ex.getMessage());

    }
    }
    }

     
  14. Hans Kristanto

    February 24, 2012 at 1:18 pm

    Hi Abdul Rahim,

    The problem is during the compilation of the .jasper file in iReport, you use the default language of groovy. To solve this, there are 2 ways. The first way is to include groovy library so that the jasper library can look for the class. But i dont like this one. I prefer the second way, to change the default language in your report designer in iReport with Java. Go to your report designer, then look at properties, then change the default language with instead of Groovy to Java.

    Hope this will help.

    Thank you.

     
  15. Abdur Rahim

    March 18, 2012 at 10:15 am

    I use netbeans plugin for ireport for produce a report and add jasper report library in my lib folder then i coded the programm as follows :-
    import java.awt.Dimension;
    import java.io.IOException;
    import java.io.InputStream;
    import java.net.URL;
    import java.sql.Connection;
    import java.sql.DriverManager;
    import java.sql.SQLException;
    import java.util.logging.Level;
    import java.util.logging.Logger;
    import javax.swing.JFrame;
    import net.sf.jasperreports.engine.JRException;
    import net.sf.jasperreports.engine.JasperFillManager;
    import net.sf.jasperreports.engine.JasperPrint;
    import net.sf.jasperreports.swing.JRViewer;

    /**
    *
    * @author Hans Kristanto
    */
    public class MainApplication {

    Connection conn = null;

    public void initConnection(){

    String HOST = “jdbc:mysql://localhost:3306/task”;
    String USERNAME = “root”;
    String PASSWORD = “tiger”;
    try {
    Class.forName(“com.mysql.jdbc.Driver”);
    } catch (ClassNotFoundException ex) {
    ex.printStackTrace();
    }

    try {
    conn = DriverManager.getConnection(HOST, USERNAME, PASSWORD);
    } catch (SQLException ex) {
    ex.printStackTrace();
    }
    }

    public void showReport() {

    //Path to your .jasper file in your package
    String reportName = “file/firstReport.jasper”;

    try {

    //Get a stream to read the file
    URL url=this.getClass().getResource(reportName);
    System.out.println(url.getPath());
    InputStream is = url.openStream();
    //InputStream in = this.getClass().getClassLoader().getResourceAsStream(reportName);

    //Fill the report with parameter, connection and the stream reader
    JasperPrint jp = JasperFillManager.fillReport(is, null, conn);

    //Viewer for JasperReport
    JRViewer jv = new JRViewer(jp);

    //Insert viewer to a JFrame to make it showable
    JFrame jf = new JFrame();
    jf.getContentPane().add(jv);
    jf.validate();
    jf.setVisible(true);
    jf.setSize(new Dimension(800,600));
    jf.setLocation(300,100);
    jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    } catch (Exception ex) {
    ex.printStackTrace();
    }
    }

    public static void main(String[] args) {

    MainApplication ma = new MainApplication();
    ma.initConnection();
    ma.showReport();
    }

    }

    When i ran through the following programm its produce following error

    Exception in thread “main” java.lang.NoClassDefFoundError: org/codehaus/groovy/control/CompilationFailedException
    at java.lang.Class.getDeclaredConstructors0(Native Method)
    at java.lang.Class.privateGetDeclaredConstructors(Class.java:2389)
    at java.lang.Class.getConstructor0(Class.java:2699)
    at java.lang.Class.newInstance0(Class.java:326)
    at java.lang.Class.newInstance(Class.java:308)
    at net.sf.jasperreports.engine.JasperCompileManager.getCompiler(JasperCompileManager.java:469)
    at net.sf.jasperreports.engine.JasperCompileManager.loadEvaluator(JasperCompileManager.java:235)
    at net.sf.jasperreports.engine.fill.JRFillDataset.createCalculator(JRFillDataset.java:427)
    at net.sf.jasperreports.engine.fill.JRBaseFiller.(JRBaseFiller.java:363)
    at net.sf.jasperreports.engine.fill.JRVerticalFiller.(JRVerticalFiller.java:77)
    at net.sf.jasperreports.engine.fill.JRVerticalFiller.(JRVerticalFiller.java:87)
    at net.sf.jasperreports.engine.fill.JRVerticalFiller.(JRVerticalFiller.java:57)
    at net.sf.jasperreports.engine.fill.JRFiller.createFiller(JRFiller.java:142)
    at net.sf.jasperreports.engine.fill.JRFiller.fillReport(JRFiller.java:52)
    at net.sf.jasperreports.engine.JasperFillManager.fillReport(JasperFillManager.java:417)
    at net.sf.jasperreports.engine.JasperFillManager.fillReport(JasperFillManager.java:378)
    at Report.MainApplication.showReport(MainApplication.java:69)
    at Report.MainApplication.main(MainApplication.java:91)

    please notify me the cause of error and what the remidies its urgent.

     
  16. Hans Kristanto

    March 18, 2012 at 11:26 am

    Hi,

    The problem is you defined the default language for the report as groovy. There are 2 ways how to solve this. Either u add library for groovy in your apps,or u change the default language in report properties in your ireport as java..

    Good luck.

     
  17. Abdur Rahim

    March 18, 2012 at 11:27 am

    Thank you sir i found the solution from your descripted way it is too much helpful for me. thank you so much! but when i set some parameter and click on preview button then it can’t generate the preview

     
  18. Hans Kristanto

    March 18, 2012 at 11:50 am

    Hi, glad to hear that it helped. Regarding the parameter setting, have you bind your report with database and make the variable?by right if you bound already,there shouldnt be any problem as long as your parameter contains the value in your db.

     
  19. Abdur Rahim

    March 19, 2012 at 7:00 am

    Sir can you help me to find out a solution of sending message via web to mobile , If some web service known to you please reffer me,I want to send the sms from my java swing application in my country india

     
  20. Abdur Rahim

    April 1, 2012 at 7:25 am

    sir when i send the parameter to jasper report it run as expected from IReport but when i run it from my application then it does not work as expected. the code given below

    public class createReport extends JPanel{

    HashMap map = new HashMap();
    JasperPrint jasperPrint = null;

    DBConnect dbc;
    Connection connection = null;

    java.util.Date start,end;
    String s;
    ComboIDSelector cids;
    protected ChooseDate SDateF,EDateF;

    JLabel idlab,Sdate;
    JButton execute;
    JPanel datePanel, idPanel, emailpanel;

    protected Image iconTasks=null;
    URL url;

    public createReport() {
    try {
    idlab=new JLabel(” Id “);
    Sdate= new JLabel(” Date in between “);
    execute=new JButton(“Execute”);

    start=new java.util.Date();
    start=this.setBeforeDate(start);
    SDateF=new ChooseDate(start);
    EDateF=new ChooseDate();

    dbc=new DBConnect();
    connection=dbc.getConn();

    cids = new ComboIDSelector(dbc);
    cids.addItem(“All”);

    datePanel = new JPanel();
    idPanel = new JPanel();
    emailpanel = new JPanel();

    datePanel.setLayout(new GridLayout(1, 3));
    idPanel.setLayout(new GridLayout(1, 3));
    emailpanel.setLayout(new GridLayout(3, 1));

    datePanel.add(Sdate);
    datePanel.add(SDateF);
    datePanel.add(EDateF);

    idPanel.add(idlab);
    idPanel.add(cids);

    emailpanel.add(datePanel);
    emailpanel.add(idPanel);
    emailpanel.add(execute);

    setBorder(new TitledBorder(“Report”));
    add(emailpanel);

    execute.addActionListener(new ActionListener() {

    public void actionPerformed(ActionEvent e) {
    start=SDateF.getDate();
    end=EDateF.getDate();
    s=cids.getSelectedId();
    if(s.equalsIgnoreCase(“All”))
    s=”%”;
    System.out.println(start+” “+end+” “+s);
    importParameter();
    }

    });

    } catch (SQLException ex) {
    JOptionPane.showMessageDialog(null, “Error during parsing document”, “Error: contact with vendor”, 1);
    System.exit(1);
    }
    }
    public void importParameter(){
    try {
    map.put(“StartDate”, start);
    map.put(“EndDate”, end);
    map.put(“Id”,s);
    URL urls=createPath(“file/taskReports.jasper”);
    InputStream is = urls.openStream();
    //InputStream is = this.getClass().getClassLoader().getResourceAsStream(“Report/file/taskReport.jasper”);
    //System.out.println(path);
    jasperPrint = JasperFillManager.fillReport(is, map, connection);
    JRViewer jv = new JRViewer(jasperPrint);
    JFrame jf = new JFrame();
    jf.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);

    jf.getContentPane().add(jv);
    jf.validate();
    jf.setVisible(true);
    jf.setSize(new Dimension(800,600));
    jf.setLocation(300,100);
    jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    } catch (Exception ex) {
    System.out.println(ex.getMessage());
    //JOptionPane.showMessageDialog(null, “Error during parsing document”, “Error: contact with vendor”, 1);
    // System.exit(1);
    }

    }
    public String setdateYYYYMMDD(java.util.Date d) {
    DateFormat df;
    df = DateFormat.getDateInstance(DateFormat.MEDIUM, Locale.JAPAN);
    return df.format(d);
    }
    public java.util.Date setBeforeDate(java.util.Date d) {
    int month = d.getMonth();
    if (month == 0) {
    d.setMonth(11);
    d.setYear(d.getYear() – 1);
    } else {
    d.setMonth(d.getMonth() – 1);
    }
    return (java.util.Date) d;
    }
    protected static URL createPath(String path) {
    java.net.URL imgURL = createReport.class.getResource(path);
    if (imgURL != null) {
    return imgURL;
    } else {
    System.err.println(“Couldn’t find file: ” + path);
    return null;
    }
    }

    }

    and .jrxml file as follows

    My problem is when i send those parameter the report does not depend on the parameter rather than it fetch all data from table . please help me to find out the solution.

     
  21. Abdur Rahim

    April 1, 2012 at 7:30 am

    My .jrxml file dont attach with it so i send it by another post

     
  22. Abdur Rahim

    April 1, 2012 at 7:45 am

    sir when i close the Frame associated with JRViewer then the application close how i can override the method associated with exit from application please help me

     
  23. Abdur Rahim

    April 1, 2012 at 7:50 am

    sir when i close the Frame associated with JRViewer then the application close how i can override the method associated with exit from application please help me. is there any other way by which i can prevent the close of application

     
  24. Hans Kristanto

    April 1, 2012 at 9:17 am

    Try to make sure your value is exist, meaning to say, debug the value.. see whether you sent the parameter to jasper with null, empty, or no value?

     
  25. Abdur Rahim

    April 1, 2012 at 7:42 pm

    sir i checked the parameter and it successfully send the value . I have three parameter two are Date and one is String.I print those value and it successfully print those value.My code given below.
    map.put(“StartDate”, start);
    map.put(“EndDate”, end);
    map.put(“Id”,s);
    URL urls=createPath(“file/taskReports.jasper”);
    InputStream is = urls.openStream();
    //InputStream is = this.getClass().getClassLoader().getResourceAsStream(“Report/file/taskReport.jasper”);
    //System.out.println(path);
    jasperPrint = JasperFillManager.fillReport(is, map, connection);
    JRViewer jv = new JRViewer(jasperPrint);
    JFrame jf = new JFrame();
    jf.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);

    jf.getContentPane().add(jv);
    jf.validate();
    jf.setVisible(true);

     
  26. Abdur Rahim

    April 2, 2012 at 10:36 am

    sir please view my problem.

     
  27. Hans Kristanto

    April 2, 2012 at 11:07 am

    have you match the parameter name with the one in .jasper?

     
  28. Abdur Rahim

    April 2, 2012 at 3:00 pm

    yes sir i send only those parameter that are written in .jrxml

     
  29. Hans Kristanto

    April 2, 2012 at 3:18 pm

    i mean, is the parameter name the same? since i dont know what you have done and i dont have access to do some troubleshooting, have you try to debug or whatever?

     
  30. Abdur Rahim

    April 2, 2012 at 8:50 pm

    sir i have tried every way as i know . My two parameter is date when i print the date(System.out.println()) then both date parameter print the date as expected and another parameter is String type when i print it ,it also produce the expected value .My parameters are StartDat,EndDate,Id in .jrxml and in the .java file i also set the parameter for StartDat,EndDate and Id. please help me to find a solution.

     
  31. Hans Kristanto

    April 2, 2012 at 9:08 pm

    I cant help to find solution, but i can help to find the workaround.. try to change the parameter, instead of StartDat, EndDate, change into something else. This is a debugging purpose where you can try to search what is the problem..

     
  32. Abdur Rahim

    April 2, 2012 at 11:27 pm

    sir is it possible to use JRViewer within a JFrame and run the application when i close the JFrame.
    I am new with JRViewer please help me with some code.

     
  33. Abdur Rahim

    April 3, 2012 at 12:20 pm

    i have solve the parameter problem but i need more about JRViewer class as a beginner i dont know for which if i close the fame related with JRViewer then the application exit . As a senior please help me.

     
  34. Hans Kristanto

    April 3, 2012 at 12:36 pm

    If you have solved your problem, can you please post here what is the solution so that other people can easily find if they have same problem with yours?

     
  35. Abdur Rahim

    April 3, 2012 at 3:19 pm

    I cannot write the second date parameter correctly.After change the second parameter the report run finely. but one more question can i customize JRViewer by which if i close the fame related with JRViewer then the application don’t exit generally it exited. how to cutomize it?

     
  36. Hans Kristanto

    April 3, 2012 at 3:29 pm

    put it under another jframe.. meaning to say that create your own jframe which is not extended with main application, then your jrviewer put it under that jframe..

     
  37. Abdur Rahim

    April 3, 2012 at 4:13 pm

    I have coded things in your specified way but it also exit.see My code is it not like that ?

    map.put(“StartDate”, start);
    map.put(“EndDate”, end);
    map.put(“Id”,s);
    URL urls=createPath(“file/taskReports.jasper”);
    InputStream is = urls.openStream();
    jasperPrint = JasperFillManager.fillReport(is, map, connection);
    JRViewer jv = new JRViewer(jasperPrint);
    JFrame jf = new JFrame();
    jf.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
    jf.getContentPane().add(jv);j
    jf.setVisible(true);
    jf.setSize(new Dimension(800,600));
    jf.setLocation(300,100);
    jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    if any wrong goes please notify me.

     
  38. Hans Kristanto

    April 3, 2012 at 4:38 pm

    did you close the parent frame or the parent frame of your jrviewer that u created separately? I think this question is more in the swing UI already.. have you try to google for it?

     
  39. jasmine

    June 26, 2012 at 4:37 pm

    Hello Hans,

    i do exactly what you tell me and i am satisfied,
    now i have another problem ,I’m working on an existante application .as i tell you the perpuse is to change the reporting tool of this application.

    The problem is that this applictaion has got a big database that contains data and also the list of all labels that needed the reports of this application. (because the application is huge, then they are many labels) ,not that the data and labels are in a same Database.

    when i prepare the jrxml (maquettes) of each report,i dont want to use statictext, i want ti use the labels existing in the Database.

    you have an idea, how can i do to retrieve thes labels , and do not use any text hard.

    jasmine
    thank you in advance

     
  40. Mohammed Sameer

    June 28, 2012 at 8:08 pm

    Hi Sir

    I created a student registration form. and have wrote to view the riport this code in netbeans but it is coming error. please help urgently……
    Code:
    try {

    String reportSource = “C:/Documents and Settings/Radh & Sameer/My Documents/NetBeansProjects/DHO Management System/report/student page one.jrxml”;
    String reportSource2 = “C:/Documents and Settings/Radh & Sameer/My Documents/NetBeansProjects/DHO Management System/report/student page two.jrxml”;

    Map params2 = new HashMap();
    Map params = new HashMap();

    params.put(“stdindexno”,txt_stdindexno.getText());

    JasperReport jasperReport2 = JasperCompileManager.compileReport(reportSource2);
    JasperReport jasperReport = JasperCompileManager.compileReport(reportSource);

    Class.forName(“com.mysql.jdbc.Driver”).newInstance();
    Connection conn = (Connection) DriverManager.getConnection(“jdbc:mysql:///dhomsystem”, “root”, “”);

    JasperPrint jasperPrint2 = JasperFillManager.fillReport(jasperReport2, params2, conn);
    JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, params, conn);

    JasperViewer.viewReport(jasperPrint2, false);
    JasperViewer.viewReport(jasperPrint, false);

    conn.close();

    } catch (Exception e) {
    e.printStackTrace();
    }

    Error:
    net.sf.jasperreports.engine.JRException: Byte data not found at location : java.io.ByteArrayInputStream@1a7ffb3
    at net.sf.jasperreports.engine.util.JRLoader.loadBytesFromLocation(JRLoader.java:467)
    at net.sf.jasperreports.engine.JRImageRenderer.getInstance(JRImageRenderer.java:175)
    at net.sf.jasperreports.engine.fill.JRFillImage.evaluateImage(JRFillImage.java:921)
    at net.sf.jasperreports.engine.fill.JRFillImage.evaluate(JRFillImage.java:870)
    at net.sf.jasperreports.engine.fill.JRFillElementContainer.evaluate(JRFillElementContainer.java:275)
    at net.sf.jasperreports.engine.fill.JRFillBand.evaluate(JRFillBand.java:426)
    at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillColumnBand(JRVerticalFiller.java:1380)
    at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillDetail(JRVerticalFiller.java:692)
    at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillReportStart(JRVerticalFiller.java:255)
    at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillReport(JRVerticalFiller.java:113)
    at net.sf.jasperreports.engine.fill.JRBaseFiller.fill(JRBaseFiller.java:891)
    at net.sf.jasperreports.engine.fill.JRBaseFiller.fill(JRBaseFiller.java:795)
    at net.sf.jasperreports.engine.fill.JRFiller.fillReport(JRFiller.java:63)
    at net.sf.jasperreports.engine.JasperFillManager.fillReport(JasperFillManager.java:402)
    at dho.management.system.StudentRegistration.btn_viewActionPerformed(StudentRegistration.java:2047)
    at dho.management.system.StudentRegistration.access$7900(StudentRegistration.java:49)
    at dho.management.system.StudentRegistration$80.actionPerformed(StudentRegistration.java:1892)
    at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1995)
    at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2318)
    at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:387)
    at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:242)
    at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:236)
    at java.awt.Component.processMouseEvent(Component.java:6267)
    at javax.swing.JComponent.processMouseEvent(JComponent.java:3267)
    at java.awt.Component.processEvent(Component.java:6032)
    at java.awt.Container.processEvent(Container.java:2041)
    at java.awt.Component.dispatchEventImpl(Component.java:4630)
    at java.awt.Container.dispatchEventImpl(Container.java:2099)
    at java.awt.Component.dispatchEvent(Component.java:4460)
    at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4577)
    at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4238)
    at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4168)
    at java.awt.Container.dispatchEventImpl(Container.java:2085)
    at java.awt.Window.dispatchEventImpl(Window.java:2478)
    at java.awt.Component.dispatchEvent(Component.java:4460)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
    at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
    at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)

     
  41. jasmine

    June 29, 2012 at 8:49 pm

    Hello
    can some one help me please ,
    i follow toto of Mr Hans but i have error

    Exception in thread “main” java.lang.NullPointerException
    at java.io.ObjectInputStream$PeekInputStream.read(ObjectInputStream.java:2265)
    at java.io.ObjectInputStream$PeekInputStream.readFully(ObjectInputStream.java:2278)
    at java.io.ObjectInputStream$BlockDataInputStream.readShort(ObjectInputStream.java:2749)
    at java.io.ObjectInputStream.readStreamHeader(ObjectInputStream.java:779)
    at java.io.ObjectInputStream.(ObjectInputStream.java:279)
    at net.sf.jasperreports.engine.util.ContextClassLoaderObjectInputStream.(ContextClassLoaderObjectInputStream.java:53)
    at net.sf.jasperreports.engine.util.JRLoader.loadObject(JRLoader.java:214)
    at net.sf.jasperreports.engine.JasperFillManager.fill(JasperFillManager.java:405)
    at net.sf.jasperreports.engine.JasperFillManager.fillReport(JasperFillManager.java:824)
    at id.hans.employee.application.Mainclass.showReport(Mainclass.java:62)
    at id.hans.employee.application.Mainclass.main(Mainclass.java:85)

    thank you in adavnce

     
  42. jasmine220302@hotmail.com

    July 2, 2012 at 3:39 am

    Mr HANS ,

    please help me,
    i have this error messgae ,i do,t find where is a pb

    Exception in thread “main” java.lang.NullPointerException
    at java.io.ObjectInputStream$PeekInputStream.read(ObjectInputStream.java:2283)
    at java.io.ObjectInputStream$PeekInputStream.readFully(ObjectInputStream.java:2296)
    at java.io.ObjectInputStream$BlockDataInputStream.readShort(ObjectInputStream.java:2767)
    at java.io.ObjectInputStream.readStreamHeader(ObjectInputStream.java:798)
    at java.io.ObjectInputStream.(ObjectInputStream.java:298)
    at net.sf.jasperreports.engine.util.ContextClassLoaderObjectInputStream.(ContextClassLoaderObjectInputStream.java:53)
    at net.sf.jasperreports.engine.util.JRLoader.loadObject(JRLoader.java:214)
    at net.sf.jasperreports.engine.JasperFillManager.fill(JasperFillManager.java:405)
    at net.sf.jasperreports.engine.JasperFillManager.fillReport(JasperFillManager.java:824)
    at id.employee.application.MainApplication.showReport(MainApplication.java:50)
    at id.employee.application.MainApplication.main(MainApplication.java:72)

    thank you

     
  43. Hans Kristanto

    July 2, 2012 at 3:59 am

    Please check your line 72 in your main class. The error is thrown there.

    Best Regards,

    Hans Kristanto

     
  44. jasmine220302@hotmail.com

    July 2, 2012 at 4:42 am

    can i send to you the code? please

     
  45. jasmine220302@hotmail.com

    July 2, 2012 at 4:43 am

    Mr Hans ,can i sent to you my code please,

     
  46. mita

    May 8, 2013 at 3:10 pm

    I ‘ve an application where a jasper report is generated and prompt the user to save it into his hard disk.I want to save it in the server and make a copy of the report to another server and after one day I want to delete/flush the report from the servers.Don’t know how to do this.Can you say how to save the report in java.Here is my code
    public static byte[] getBLReportBytes(String sRptName,String params,String sRptType)
    {
    //String folder = “D:\\kamrul\\Java Projects\\DBBLReportService\\web\\reports\\cc\\”;
    String pdf_folder = “//mbreport//apache-tomcat//webapps//DBBLReportService//reports//bl//pdf//”;
    String csv_folder = “//mbreport//apache-tomcat//webapps//DBBLReportService//reports//bl//csv//”;

    String report_name = sRptName+”.jasper”;
    String pd_file_name = pdf_folder + report_name;
    String csv_file_name = csv_folder + report_name;
    byte[] bytes = null;

    try
    {
    HashMap hm = new HashMap();

    if(params != null)
    {
    if(!params.equals(“”))
    {
    log.info(“Report Param : “+params);
    String split_param []=params.split(“@”);
    String tmp_param [];
    for(int i=0;i<split_param.length;i++)
    {
    tmp_param=split_param[i].split("=");
    hm.put(tmp_param[0], tmp_param[1].replaceAll("NULL", ""));
    }
    }
    }

    try
    {
    Connection con=ConnectionHandler.getConnection();

    log.info("Generating report……….");
    if(sRptType.equals("PDF"))
    {
    log.info("Report file : "+pd_file_name);
    bytes = JasperRunManager.runReportToPdf(pd_file_name,hm, con);
    }
    else if(sRptType.equals("CSV"))
    {
    log.info("Report file : "+csv_file_name);
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    JasperPrint jasperPrint = JasperFillManager.fillReport(csv_file_name,hm, con);
    JRCsvExporter csvExporter = new JRCsvExporter();
    csvExporter.setParameter(JRCsvExporterParameter.FIELD_DELIMITER,",");
    csvExporter.setParameter(JRCsvExporterParameter.RECORD_DELIMITER,"\n");
    csvExporter.setParameter(JRCsvExporterParameter.JASPER_PRINT,jasperPrint);
    csvExporter.setParameter(JRCsvExporterParameter.OUTPUT_STREAM,baos);
    csvExporter.exportReport();
    bytes=baos.toByteArray();
    }

    con.close();

    }
    catch (JRException e)
    {
    e.printStackTrace();
    log.error(e.getMessage());
    }
    }
    catch(Exception e)
    {
    e.printStackTrace();
    log.error(e.getMessage());
    }

    if(bytes==null)
    {
    log.info("Report is Empty");
    }
    else
    {
    log.info("Report length : "+bytes.length);
    }

    return bytes;
    }

     
  47. security alarm in Shelbyville

    July 25, 2013 at 4:55 pm

    Professional roofers won’t be annoyed when you take the time to investigate your potential Window Replacement Faq would prefer you not to see. Electrical window replacement faq companies and their electricians can provide generator installation and surge protection from surge protectors. Weed out the auditors who don’t match: Match each auditor’s skills and knowledge to safely and expertly removes items from around an individual’s property or business.
    Secondly, choose the right style of replacement window an aesthetically satisfying and secure option.

     
  48. ilaiyanila

    September 21, 2013 at 12:45 am

    hi friend, it is very very help full for me,but i have tons & tons of doubts,
    the most important one is,
    ******.In SQL what is the server name? wheather it’s my pc name?**********
    and one more thing
    ******in this case , i want to use a button, on clicking that button a pdf should be created that contains the informations that are stored in the database**************
    i need this for library management system,
    where i want to generate a report for book lending status & book holders ,,,,,,,,,,,,,,,,,

     
  49. spay and neuter

    July 15, 2014 at 10:46 am

    Marvelous, what a webpage it is! This website presents valuable data to
    us, keep it up.

     
  50. hearing screenings

    July 27, 2014 at 3:54 am

    I am really enjoying the theme/design of your website.

    Do you ever run into any web browser compatibility issues? A
    couple of my blog visitors have complained about my blog
    not working correctly in Explorer but looks great in Safari.
    Do you have any advice to help fix this issue?

     
  51. sales

    August 26, 2014 at 8:00 pm

    If some one desires expert view concerning running a blog after that i advise him/her to pay a visit this web site, Keep up the
    fastidious work.

     
  52. wealthy affiliate university

    September 10, 2014 at 2:10 am

    Everything is very open with a very clear explanation of
    the challenges. It was really informative. Your
    website is very useful. Thanks for sharing!

     
  53. Prty Plan Companies

    September 10, 2014 at 12:14 pm

    Definitely consider that whch you stated. Your
    favourite justification seemed to be oon the web the easiest
    thing to take into account of. I say to you, I definitely get annoyed
    while people consider worries that they just don’t
    realize about. You managed to hit the nail upon the highest and outlined out the whole thing without
    having side-effects , people cann take a signal.
    Will probably be again to get more. Thank you

     
  54. marketing technique

    September 20, 2014 at 8:11 pm

    This is my first time visit at here and i am genuinely pleassant to read all at one place.

     
  55. marketing newbies

    September 21, 2014 at 11:35 am

    Paragraph writing is also a fun, if you be familiar with afterward you can write if not it is complicated to write.

     

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: