How to connect JasperRerport to print certain data from Postgress db in netbeans
How to connect JasperRerport to print certain data from Postgress db in netbeans
I am trying to generate some reports using JasperReports
this is what I've done so far.
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
Connection conn = null;
try{
Class.forName("org.postgresql.postgresql-42.2.2");
conn = DriverManager.getConnection("jdbc:postgresql://localhost:5432/test", "postgres", "testPassword");
String report = "";
JasperReport jasperReport = JasperCompileManager.compileReport(report);
JasperPrint jp = JasperFillManager.fillReport(jasperReport, null, conn);
JasperExportManager.exportReportToPdfStream(jp, response.getOutputStream());
response.getOutputStream().flush();
response.getOutputStream().close();
}catch(Exception ex){
System.out.println(ex);
}
}
I did all this with the help of this video
But the "response.getOutputStream()" doesnt work.
it wont find the response variable. (the tutorial is made in eclipse so thought that is the cause ,or netbeans wont be able to find it..
What can be the solution for this?
do you have any other way how to do it?
I have designed an app that will generate certain reports, its written in netbeans. and I want to connect postgresql with Jasper Reprot
– BTEK
Jun 29 at 8:55
What do you want to do with the report generated?
– Usagi Miyamoto
Jun 29 at 8:57
Your PDF export code seem to be from a Servlet, where
response
is the variable to hold the response to the browser... Your method seems to be a Swing action (a button press) where there is no response to a browser. You might want to save the PDF to a file...– Usagi Miyamoto
Jun 29 at 9:02
response
Ok, First download the ireport using this link sourceforge.net/projects/ireport , then i will ask you for database connection select "Database JDBC Connection" -->Next--> Select PostgreSQL JDBC connection " PostgreSQL (org.postgresql.Driver)" in JDBC url pass the correct hostname,database name and port number ..
– Pawan Sharma
Jun 29 at 9:02
1 Answer
1
Use JasperExportManager.exportReportToPdfFile()
to save PDF to a file:
JasperExportManager.exportReportToPdfFile()
JasperExportManager.exportReportToPdfFile(jp, "path/to/file.pdf");
If you just want to show it on the screen: Use JasperViewer.viewReport()
to display it in a window.
JasperViewer.viewReport()
JasperViewer.viewReport(jp, false);
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
You want to connect PostgreSQL database with Jasper report Studio or with iReport to generate the report using PostgreSQL database right?
– Pawan Sharma
Jun 29 at 8:47