JavaFX 8 Tutorial 62 - Jasper Report
JavaFX 8 Tutorial 62 –
Jasper Report
Jasper Report
Steps:
1. Download Jasper Report Jar
2. Download iReport Plugin
for Netbeans
for Netbeans
Link –
3. To install iReport
Plugin go to -> Tools -> Plugin -> Dowloaded -> Add Plugins.
Plugin go to -> Tools -> Plugin -> Dowloaded -> Add Plugins.
4. Add Database jar (in my
case its sqlite-jdbc.jar) and Project Jar (User_Info_App.jar) to
iReport classpath, to do so go to -> Tools -> Options -> select
iReport -> Add Database and Project
jar.
case its sqlite-jdbc.jar) and Project Jar (User_Info_App.jar) to
iReport classpath, to do so go to -> Tools -> Options -> select
iReport -> Add Database and Project
jar.
5. On welcome to iReport
Page click on step 1 -> create new Database JDBC Connection -> Give
Page click on step 1 -> create new Database JDBC Connection -> Give
· Name – Demo
· JDBC Driver – org.sqlite.JDBC
· JDBC URL - jdbc:sqlite:C:\Users\RAM
ALAPURE\Documents\NetBeansProjects\User Info App\UserDatabase.sqlite
ALAPURE\Documents\NetBeansProjects\User Info App\UserDatabase.sqlite
6. On welcome to iReport
Page click on step 2 -> select blank report -> Open This Template ->
Give
Page click on step 2 -> select blank report -> Open This Template ->
Give
· Report Name – Jasper
Report
Report
· Location – Project
Location
Location
· File – Jasper Report
File Name with Location
File Name with Location
Or
Right click on project
package -> select New -> Empty Report -> Give Name and Location.
package -> select New -> Empty Report -> Give Name and Location.
7. Click on database icon
next to preview -> write query (e.g. select * from userdatabase) ->
Preview Data.
next to preview -> write query (e.g. select * from userdatabase) ->
Preview Data.
8. Then Add Title to
report by using Static Text in iReport Palette -> Add Page X of Y in Page
Footer -> Add Fields by using Report Inspector (select the required fields and
drag into Detail.) -> Preview.
report by using Static Text in iReport Palette -> Add Page X of Y in Page
Footer -> Add Fields by using Report Inspector (select the required fields and
drag into Detail.) -> Preview.
9. Go to the Project -> Libraries -> Add
Library -> Create -> Add Jars from lib and dist directory.
Library -> Create -> Add Jars from lib and dist directory.
10.
Create new Button(“Report”) and add to the scene. To print
Jasper Report create a class PrintReport by extending JFrame. Add method
showReport() to display report.
Create new Button(“Report”) and add to the scene. To print
Jasper Report create a class PrintReport by extending JFrame. Add method
showReport() to display report.
// UserInfoApp.java
Button report = new Button("Report");
report.setFont(Font.font("SanSerif", 15));
report.setOnAction(e ->{
PrintReport viewReport = new PrintReport();
viewReport.showReport();
});
HBox hbox = new HBox(5);
hbox.getChildren().addAll(load, delete,update, comboBox, exportToXL, importXLToDB, report);
//PrintReport.java
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package org.ramalapure.userinfoapp;
import java.awt.HeadlessException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import net.sf.jasperreports.engine.JasperCompileManager;
import net.sf.jasperreports.engine.JasperFillManager;
import net.sf.jasperreports.engine.JasperPrint;
import net.sf.jasperreports.engine.JasperReport;
import net.sf.jasperreports.view.JRViewer;
/**
*
* @author Ram
*/
public class PrintReport extends JFrame{
Connection conn = SqlConnection.DbConnector();// Database Connection
PreparedStatement pst = null;
ResultSet rs = null;
public PrintReport() throws HeadlessException {
}
public void showReport(){
try {
JasperReport jasperReport = JasperCompileManager.compileReport("C:\\Users\\RAM ALAPURE\\Documents\\NetBeansProjects\\User Info App\\src\\org\\ramalapure\\userinfoapp\\newReport1.jrxml");
JasperPrint JasperPrint = JasperFillManager.fillReport(jasperReport, null, conn);
JRViewer viewer = new JRViewer(JasperPrint);
viewer.setOpaque(true);
viewer.setVisible(true);
this.add(viewer);
this.setSize(900,500); // JFrame size
this.setVisible(true);
} catch (Exception e) {
JOptionPane.showMessageDialog(rootPane, e.getMessage());
}
}
}
Comments
Post a Comment