Create Jasper Report in NetBeans



STEP 1: Download ireport plugin for Netbeans

STEP 2: Install plugin in Netbeans
·        Click tools --> select option  plugin


·        Select Downloaded tab --> click Add Plugin Button --> Browse and select your plugin from system location --> click open button
·        After that Click Install button --> Next --> Install --> Validation warning dialog box appear  Click Continue Button --> click finish

STEP3: Right click your project and select Empty report


STEP 4: select this database icon and create database link

STEP 5: Create Sample Jasper Report and select database icon next to preview button

  •  After that drag and drop text field
  • Right click -->select Edit expression and
  • Select your table field here


STEP 6: Call Jasper Report from Java code with database  connection
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import net.sf.jasperreports.engine.*;

import net.sf.jasperreports.engine.export.JRXlsAbstractExporterParameter;
import net.sf.jasperreports.engine.export.JRXlsExporter;
import net.sf.jasperreports.view.JasperViewer;
/**
 *
 * @author ganesh
 */
public class anand {
    public static void main(String[] args) throws IOException
    {
          try
        {
      
//Specify Your Report Path
JasperReport jasperReport=JasperCompileManager.compileReport("Report\\report3.jrxml");
        
            Class.forName("com.mysql.jdbc.Driver");

            Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/tally" , "root", "root");
Statement stmt = null;
ResultSet rset = null;
String queryString = "SELECT category.`accountno` AS category_accountno, category.`name` AS category_name,category.`type` AS category_type FROM `category` category WHERE accountno BETWEEN 100 and 111";
stmt = conn.createStatement();
rset = stmt.executeQuery(queryString);
 JRResultSetDataSource jasperReports = new JRResultSetDataSource(rset);

            JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport,null, jasperReports);
//Report saved in specified path
            JasperExportManager.exportReportToPdfFile(jasperPrint,"D:\\b1.pdf");
//Report open in Runtime
          Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler " +"D:\\b1.pdf");
JRXlsExporter exporterXLS = new JRXlsExporter();
OutputStream output = new FileOutputStream(new File("D:\\b1.xls"));
 exporterXLS.setParameter(JRExporterParameter.JASPER_PRINT,jasperPrint);
 exporterXLS.setParameter(JRExporterParameter.OUTPUT_STREAM, output);
 exporterXLS.setParameter(JRXlsAbstractExporterParameter.IS_COLLAPSE_ROW_SPAN, Boolean.TRUE);
 exporterXLS.setParameter(JRXlsAbstractExporterParameter.IS_REMOVE_EMPTY_SPACE_BETWEEN_COLUMNS, Boolean.TRUE);
 exporterXLS.setParameter(JRXlsAbstractExporterParameter.IS_REMOVE_EMPTY_SPACE_BETWEEN_ROWS, Boolean.TRUE);
 exporterXLS.setParameter(JRXlsAbstractExporterParameter.IS_ONE_PAGE_PER_SHEET, Boolean.FALSE);
 exporterXLS.setParameter(JRXlsAbstractExporterParameter.IS_DETECT_CELL_TYPE, Boolean.FALSE);
 exporterXLS.setParameter(JRXlsAbstractExporterParameter.IS_WHITE_PAGE_BACKGROUND, Boolean.FALSE);
 exporterXLS.setParameter(JRXlsAbstractExporterParameter.IS_IGNORE_GRAPHICS, Boolean.TRUE);
 exporterXLS.exportReport();
            //JasperViewer.viewReport(jasperPrint);

        }
 catch (JRException e)
        {
            e.printStackTrace();
        }
        catch (ClassNotFoundException ex)
        {
            ex.printStackTrace();
        }
        catch (SQLException ex)
        {
            ex.printStackTrace();
        }
    }
}

Required  Jar Files:
  1.             commons-beanutils-1.8.2.jar
    2.      commons-collections-3.2.1.jar
    3.      commons-digester-2.1.jar
    4.      commons-logging-1.1.1.jar
    5.      groovy-all-1.7.5.jar
    6.      iText-2.1.7.jar
    7.      jasperreports-4.5.1.jar
    8.      jdt-compiler-3.1.1.jar
    9.      mysql-connector-java-5.1.6-bin.jar
    10.  poi-3.7-20101029.jar
    11.  rs2xml.jar






9 comments:

  1. Anonymous said...:

    very useful for me..thank u...

  1. Unknown said...:

    thank u so much....

  1. Anonymous said...:

    It is very easy to understand .Very nice!!!!!!!.Thank you.......

  1. jpnimbark said...:

    does jasper reports supports mysqli database ?????

  1. Unknown said...:

    It supports because mysqli is a new version of the mysql

  1. Anonymous said...:

    I've some problem in add plugin in netbeans.......after download the ireport i attach the downloaded plugin,it is not showned.pls help me resolve this problem..................










  1. Anonymous said...:

    Thanks Very Useful for Me

  1. Akshit Arora said...:

    It would be helpful if you could post a new blog entry with the new JasperSoft Studio linking with Netbeans.

  1. Anonymous said...:

    I really appreciate information shared above. It’s of great help. If someone want to learn Online (Virtual) instructor lead live training in Netbeans, kindly Contact MaxMunus
    MaxMunus Offer World Class Virtual Instructor led training on Netbeans. We have industry expert trainer. We provide Training Material and Software Support. MaxMunus has successfully conducted 1,00,000 + trainings in India, USA, UK, Australlia, Switzerland, Qatar, Saudi Arabia, Bangladesh, Bahrain and UAE etc.
    For Demo Contact us.
    Akash Kumar Asthana
    MaxMunus
    E-mail: Nitesh@maxmunus.com
    Skype id: nitesh_maxmunus
    Contact No: 8553912023
    www.MaxMunus.com



Post a Comment

 
java4practices © 2013 | Designed by Ganesh Rengarajan