First of all I am a beginner at using jasper ireport and I am trying to generate a jasper ireport when a user is putting a value in a jtextfield, and then pressing a button, it should generate a report in PDF for Invoice. This is the first time I am using java netbeans with jasper ireport.
So how do I generate an ireport when the user have put its value in the jtextfield and then pressed a button, where it then should generate a invoice report in PDF, using java netbeans?
I have created an invoice in ireport 4.7.1 and posted the code below for the print button regardign the invoice, but when I hit the button it loads all invoices located in my project.
String invreport = "C:\\Users\\Silent Heart\\Documents\\NetBeansProjects\\SIS\\src\\reports\\invoice.jrxml";
JasperReport jpr = JasperCompileManager.compileReport(invreport);
JasperPrint jpp = JasperFillManager.fillReport(jpr, null,conn);
JasperViewer.viewReport(jpp);
This is a snapshot of what is happening:
i solved my problem.
First add parameter like " testid "
in jasper ireport parameter area then add this parameter in query of your database in jasper ireport like
"select * from test where id = $P{testid}"
then add below code for button:
// parameter
String para = txt1.getText();
//load report location
FileInputStream fis = new FileInputStream("\\src\\test\\report1.jrxml");
BufferedInputStream bufferedInputStream = new BufferedInputStream(fis);
//set parameters
Map map = new HashMap();
map.put("testid", para);
//compile report
JasperReport jasperReport = (JasperReport) JasperCompileManager.compileReport(bufferedInputStream);
JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, map, conn);
//view report to UI
JasperViewer.viewReport(jasperPrint, false);
for PDF use " JasperExportManager "
I hope it will work for you.
Thanks..