Posts

Showing posts from June, 2022

jasper report from java program

  How to run Jasper report from Java Program Pass Parameters from Java Program to Jasper Report, user enters three Parameters in order to run report. First make Connection to connect Mysql database from Java form(described eariler), then pass parameters using Hashmap .First parameter is report parameter , second parameter is user entered parameter such as in this case a.put("sclass",dispclass.getText()); First parameter is sclass(defined in report) , second is dispclass(defined in Java form). Call jrxml file with full path to run the report.. remaining code is easy to follow.. public void load_report() throws Exception { try {     Connection conn=getConnection();     HashMap a = new HashMap();     a.put("sclass",dispclass.getText());     a.put("stud_sec",dispsec.getText());     a.put("user_year",dispyear.getText());       String report = "C:\\mps\\fee\\mps_fee\\nominal_roll.jrxml"; ...
Image
Design Simple Report in Jasper Report GUI. As in most GUI based Report writer and Form Designer, user select various Designer objects  such as Textboxes, Radio buttons , Dropdown List item. etc.. Report writer generates source code and its properties for user.Below is such sample source code taken from Jasper report writer in which three  parameters are passed(user input) to run the query(in sql).Pay close attention how to pass parameters in Sql query(in jasper report $ sign placed before Parameters and Fields like $P{} denotes Parameters and $F{} denotes reports fields. As user design report further ,report writer automatically generates code for that. There are many predefined functions both text and numeric functions such as to convert string into numeric or Dates into String etc, and numeric functions like sum(),max(),min(),avg() and many more...    <parameter name="sclass" class="java.lang.String"> <defaultValueExpression><![CDATA[$P{sclass}]]...
 In Next few articles, I explore JASPER Reports a Java Library which has 2D,3D,Line,Pie,Bar chart. One can easily display Graph/Chart based on sql Query ie Data fetched by SQL and same data is used to Display in Chart/Graph format. One has to import certain Java Library in your Java Program in order to run /Display chart. Jasper Report is a component in JasperSoft Studio which is free ,just Download from internet  and install on your computer. Jasper Report generates two files one is Designed Report and other is Compiled Report. Designed Report file is jrxml source file  with jrxml file extension and Compiled Report file is Jasper Source file with Jasper file extension(.Jasper)  it has GUI based editor and variety of reports templates such as  1.) Form based 2.)Group (Break) 3.) Matrix  etc... will show how to create Simple Jasper report in next Article...  
 Parameters Passing between Two Java Programs Below code executes when User clicks on menu item Student Dashboard ,two parameters namely School Name(Sch_name) and School Year (Sch_year) got populated when user enters School name,School_year in login form. These two parameters passes into Student Dashboard form and Display on that form. When user opens(clicks on Student Dashboard) form. public void actionPerformed(ActionEvent e) { String Sch_name = school_name.getText(); String School_year = Sch_year.getText(); new Student_DashBoard(Sch_name,School_year).setVisible(true); Below code is executes when Student Dasboard menu item clicked. Notice these two parameters(Name of two parameters should remain exactly same) public static void main(String[] args) { EventQueue.invokeLater(new Runnable() { public void run(String Sch_name,String School_year) { try { Student_DashBoard frame = new Student_DashBoard(Sch_name,School_year); frame.setVisible(true); ...