For Netbeans IDE you have to install Plug-in from here.
Steps for creating report using Netbeans-:
Step I-: Go to File Menu and Choose New File
Step II -: Click on Report Folder and choose Report Wizard . Click Next
Step III -: Select any Format of report. Click Next
Step IV -: Name the Report . Click Next
Note -: While naming dont remove the .jrxml extension... edit before the extension
Step V -: Select Empty Data Source and click next
Step VI -: Click Next. Then Next and Then Finish.
Now You have created a report . Now you have to design it accordingly.
Designing a report -:
You will notice a report file in your software package generally in the left side of Netbeans.
Click on the Report .
A Blank Page will appear.
Delete all the partitions of the page .
Using Report Inspector Tool in the left bottom of netbeans.
Right click on each band and select Delete Band. (Don't delete Title , Detail and background).
Now Design the Report using Report Elements present in the upper right corner in Netbeans.
Choose Static Text for Labels that will remain unchanged like Title ,Address etc..
TextFields for filling data from Database.
Now rename the TextFields with the name of ur column in database . For example column name in your database is stu_name for student name then rename the textfield name as " $F{stu_name} ".
Rename all your fields with that in your database one.
Click on Datasource and select New from the new window appeared.
Select Database type.
Enter you Connection String and URL and desired connection Name.
Click Test to test the connection is successful.
After that select the Data Source you have created.
The Last step is to write the code to call iReport from your program in action of button or anywhere you desire.
try
{
JasperDesign jd=JRXmlLoader.load("src\\collegemaagement\\report3.jrxml"); // Full address of you Report in between the ""
String sql="SELECT student_fee_detail.fee_paid, student_fee_detail.receipt_no, student_fee_detail.type,student_fee_detail.mode,student_fee_detail.date_of_payment,student_detail.stu_name,student_detail.admno, student_detail.father_name,student_detail.branch,student_detail.batch FROM student_fee_detail ,student_detail WHERE student_fee_detail.admno = student_detail.admno AND student_fee_detail.receipt_no= '"+rcpno+"'";
// sql is the query to get data from database
System.out.println("Query");
JRDesignQuery newQuery=new JRDesignQuery();
newQuery.setText(sql);
jd.setQuery(newQuery);
JasperReport jasperReport = JasperCompileManager.compileReport(jd);
JasperPrint jasperprint = JasperFillManager.fillReport(jasperReport, null,conn);
JasperViewer.viewReport(jasperprint,false);
}
catch(Exception ex)
{
JOptionPane.showMessageDialog(null, ex.getMessage(),"Messege",JOptionPane.PLAIN_MESSAGE);
System.out.println(ex);
}
Now The Final report will Appear as in the figure below-:
Comment for any Query.
0 Comments