title: how can i show a report when I click a button in java program using netbeans plugin IReport
body: <p>I am creating a program that will show the data inside the table of a database, I use IReport plugin for netbeans to create a report for that. I want to call that report when i click the a button . but it gives me this error,</p>
  
  <pre><code>Exception in thread "AWT-EventQueue-0" java.lang.NoClassDefFoundError: org/apache/commons/logging/LogFactory
  at net.sf.jasperreports.engine.util.JRLoader.&lt;clinit&gt;(JRLoader.java:65)
  at net.sf.jasperreports.engine.JRPropertiesUtil.loadProperties(JRPropertiesUtil.java:99)
  at net.sf.jasperreports.engine.DefaultJasperReportsContext.initProperties(DefaultJasperReportsContext.java:95)
  at net.sf.jasperreports.engine.DefaultJasperReportsContext.&lt;init&gt;(DefaultJasperReportsContext.java:72)
  at net.sf.jasperreports.engine.DefaultJasperReportsContext.&lt;clinit&gt;(DefaultJasperReportsContext.java:60)
  at net.sf.jasperreports.engine.JasperCompileManager.getDefaultInstance(JasperCompileManager.java:83)
  at net.sf.jasperreports.engine.JasperCompileManager.compileReport(JasperCompileManager.java:448)
  at RecordManagementSystem.connection$thehandler.actionPerformed(connection.java:270)
  at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2018)
  at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2341)
  at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:402)
  at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:259)
  at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:252)
  at java.awt.Component.processMouseEvent(Component.java:6505)
  at javax.swing.JComponent.processMouseEvent(JComponent.java:3320)
  at java.awt.Component.processEvent(Component.java:6270)
  at java.awt.Container.processEvent(Container.java:2229)
  at java.awt.Component.dispatchEventImpl(Component.java:4861)
  at java.awt.Container.dispatchEventImpl(Container.java:2287)
  at java.awt.Component.dispatchEvent(Component.java:4687)
  at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4832)
  at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4492)
  at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4422)
  at java.awt.Container.dispatchEventImpl(Container.java:2273)
  at java.awt.Window.dispatchEventImpl(Window.java:2719)
  at java.awt.Component.dispatchEvent(Component.java:4687)
  at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:735)
  at java.awt.EventQueue.access$200(EventQueue.java:103)
  at java.awt.EventQueue$3.run(EventQueue.java:694)
  at java.awt.EventQueue$3.run(EventQueue.java:692)
  at java.security.AccessController.doPrivileged(Native Method)
  at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
  at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:87)
  at java.awt.EventQueue$4.run(EventQueue.java:708)
  at java.awt.EventQueue$4.run(EventQueue.java:706)
  at java.security.AccessController.doPrivileged(Native Method)
  at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
  at java.awt.EventQueue.dispatchEvent(EventQueue.java:705)
  at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:242)
  at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:161)
  at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:150)
  at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:146)
  at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:138)
  at java.awt.EventDispatchThread.run(EventDispatchThread.java:91)
      Caused by: java.lang.ClassNotFoundException: org.apache.commons.logging.LogFactory
  at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
  at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
  at java.security.AccessController.doPrivileged(Native Method)
  at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
  at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
  at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
  at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
  ... 44 more
  </code></pre>
  
  <p>I think this is the part where i get my errors : </p>
  
  <pre><code>   if(event.getSource()==show){
         try{  
             String path = "C:\\NetBeansProjects\\SADSIGN\\src\\RecordManagementSystem\\report2.jrxml";                 
            JasperReport jr = JasperCompileManager.compileReport(path);
            JasperPrint jp =  JasperFillManager.fillReport(jr, null,con);
            JasperViewer.viewReport(jp);
            }catch(Exception e){
             JOptionPane.showMessageDialog(null, save);
               }
                   }
  </code></pre>
  
  <p>here is my whole code : </p>
  
  <pre><code>  import java.sql.*;
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    import net.sf.jasperreports.view.*;
    import net.sf.jasperreports.engine.*;
  
    public class connection extends JFrame {
  
       Connection con;
       Statement st;
       ResultSet rs;
  
      private JTextField t1;
      private JTextField t2;
      private JTextField t3;
      private JButton b1;
      private JButton b2;
      private JButton b3;
      private JButton b4;
      private JButton ud;
      private JButton del;
      private JButton nw;
      private JButton save;
  
              private JButton show;
  
      public connection(){        
          connect();
          createFrame();
      }
  
      public void connect(){
          try{    
              String driver = "sun.jdbc.odbc.JdbcOdbcDriver";
              Class.forName(driver);
  
              String connect = "jdbc:odbc:RIM";
              con = DriverManager.getConnection(connect);
  
              st = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE);
              String sql = "select * from test";
              rs = st.executeQuery(sql);
  
          }catch(Exception e){}   
      }
  
      public void createFrame(){
          setLocationRelativeTo(null);
          setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          getContentPane().setLayout(null);
          setVisible(true);
          setSize(480,200);
          getContentPane().setBackground(Color.GRAY);
  
          JLabel first = new JLabel("First name");
          first.setBounds(40, 11, 75, 14);
          getContentPane().add(first);
  
          t1 = new JTextField();
          t1.setBounds(102, 8, 108, 20);
          getContentPane().add(t1);
          t1.setColumns(10);
  
          JLabel last = new JLabel("Last Name");
          last.setBounds(220, 11, 75, 14);
          getContentPane().add(last);
  
          t2 = new JTextField();
          t2.setBounds(288, 8, 100, 20);
          getContentPane().add(t2);
          t2.setColumns(10);
  
          JLabel age = new JLabel("Age");
          age.setBounds(138, 39, 46, 14);
          getContentPane().add(age);
  
          t3 = new JTextField();
          t3.setBounds(187, 39, 108, 20);
          getContentPane().add(t3);
          t3.setColumns(10);
  
          b1 = new JButton("next");
          b1.setBounds(40, 78, 75, 23);
          getContentPane().add(b1);
  
          b2 = new JButton("prev");
          b2.setBounds(123, 78, 75, 23);
          getContentPane().add(b2);   
  
          b3 = new JButton("last\r\n");
          b3.setBounds(208, 78, 75, 23);
          getContentPane().add(b3);
  
          b4 = new JButton("first");
          b4.setBounds(299, 78, 89, 23);
          getContentPane().add(b4);
  
          ud = new JButton("Update");
          ud.setBounds(26, 123, 89, 23);
          getContentPane().add(ud);
  
          del = new JButton("Delete");
          del.setBounds(123, 123, 89, 23);
          getContentPane().add(del);
  
          nw = new JButton("New");
          nw.setBounds(225, 123, 89, 23);
          getContentPane().add(nw);
  
                      show = new JButton("show");
                      show.setBounds(400,123,89,23);
                      getContentPane().add(show);
  
          save = new JButton("save");
          save.setBounds(324, 123, 89, 23);
          getContentPane().add(save);
  
          try{
              rs.next();
              t1.setText(rs.getString("Fname"));
              t2.setText(rs.getString("Lname"));
              t3.setText(rs.getString("Age"));
  
  
          }catch(Exception e){
  
          }
          thehandler handler = new thehandler();
          b1.addActionListener(handler);
          b2.addActionListener(handler);
          b3.addActionListener(handler);
          b4.addActionListener(handler);
          ud.addActionListener(handler);
          del.addActionListener(handler);
          nw.addActionListener(handler);
          save.addActionListener(handler);
                      show.addActionListener(handler);
              }
  
  
  
  
  
  
  private class thehandler implements ActionListener{
              public void actionPerformed(ActionEvent event){
                  if(event.getSource()==b1){
                      try{    
                          if(rs.next()){
                              t1.setText(rs.getString("fname"));
                              t2.setText(rs.getString("lname"));
                              t3.setText(rs.getString("age"));        
  
                          }else{
  
                              JOptionPane.showMessageDialog(null, "No more records");
                              rs.previous();
                          }
                      }catch(Exception e){}
                  }
  
                  if(event.getSource()==b2){
                      try{                        
                          if(rs.previous()){
                              t1.setText(rs.getString("fname"));
                              t2.setText(rs.getString("lname"));
                              t3.setText(rs.getString("age"));        
  
                          }else{
  
                              JOptionPane.showMessageDialog(null, "No more records");
                              rs.next();
                          }
                      }catch(Exception e){}
                  }
  
                  if(event.getSource()==b3){
                      try{
                          rs.last();
                          t1.setText(rs.getString("fname"));
                          t2.setText(rs.getString("lname"));
                          t3.setText(rs.getString("age"));
                      }catch(Exception e){}
                  }
                  if(event.getSource()==b4){
                      try{
                          rs.first();
                          t1.setText(rs.getString("fname"));
                          t2.setText(rs.getString("lname"));
                          t3.setText(rs.getString("age"));
  
                      }catch(Exception e){}
                  }
                  if(event.getSource()==ud){
                      String fname = t1.getText();
                      String lname = t2.getText();
                      String age = t3.getText();
  
                      try{
                          rs.updateString("fname", fname);
                          rs.updateString("lname", lname);
                          rs.updateString("age", age);                
                          rs.updateRow();
  
                          JOptionPane.showMessageDialog(null, "Record updated successfully");
                      }catch(Exception e){}
                  }
  
                  if(event.getSource()==del){
                      try{
                          rs.deleteRow();
  
                          t1.setText("");
                          t2.setText("");
                          t3.setText("");
  
  
  
                          if(rs.last()){
                              rs.previous();
                              t1.setText(rs.getString("fname"));
                              t2.setText(rs.getString("lname"));
                              t3.setText(rs.getString("age"));
  
  
                          }else if(rs.first()){
                          rs.next();
                          t1.setText(rs.getString("fname"));
                          t2.setText(rs.getString("lname"));
                          t3.setText(rs.getString("age"));
                          }
  
  
                      }catch(Exception e){}
                  }
  
                  if(event.getSource()==nw){
                      t1.setText(" ");
                      t2.setText(" ");
                      t3.setText(" ");
                  }
  
                  if(event.getSource()==save){
                      String lname = t1.getText();
                      String fname = t2.getText();
                      String age = t3.getText();
                      JOptionPane.showMessageDialog(null, "Record Successfully added");
  
  
                      try{
                          rs.moveToInsertRow();
  
                          rs.updateString("fname", lname);
                          rs.updateString("lname", fname);
                          rs.updateString("age", age);
                          rs.insertRow();
  
                          rs.next();
  
                          t1.setText(rs.getString("fname"));
                          t2.setText(rs.getString("lname"));
                          t3.setText(rs.getString("age"));
  
                      }catch(Exception e){}
                  }
  
                                  if(event.getSource()==show){
                                   try{   
                                      String path = "C:\\NetBeansProjects\\SADSIGN\\src\\RecordManagementSystem\\report2.jrxml";                    
                                      JasperReport jr = JasperCompileManager.compileReport(path);
                                      JasperPrint jp =  JasperFillManager.fillReport(jr, null,con);
                                      JasperViewer.viewReport(jp);
                                   }catch(Exception e){
                                       JOptionPane.showMessageDialog(null, save);
                                   }
                                  }
              }
          }
     public static void main(String[] args) {
         new connection();
     }
  }
  </code></pre>