in my Java project, I have many JasperReports reports with complex SQL queries containing many parameters. Reports are used to create pdf documents containing data returned by the request, grouped and formatted in various ways.
Now I also have the need to directly export the result of the query (for example, a ResultSet or Map or CSV file or similar ...). Is it possible to request JasperReports to execute only the query and return the results instead of rendering the pdf page?
(NOTE: this is not the same as choosing the csv output format for rendering the report, since this method tries to convert the report project to a csv file ... Instead, I would only like to βreuseβ the request inside the report, also using JR parameter management etc.)
This is my Java code to create a pdf from a report:
JasperReport report = (JasperReport) JRLoader.loadObject(inStream); JasperPrint jasperprint = JasperFillManager.fillReport(report, params, conn); JRAbstractExporter exporter = new JRPdfExporter(); exporter.exportReport(); ByteArrayOutputStream os = (ByteArrayOutputStream) exporter.getParameter(JRExporterParameter.OUTPUT_STREAM); byte[] formattedReportBytes = os.toByteArray(); return formattedReportBytes;
I saw there a class called JRJdbcQueryExecuter
inside JasperReports ... Is it possible to call it directly, instead of calling fillReport
, to get the ResultSet from the executed SQL query?
thanks
source share