im trying to export a jrxml file to pdf, but i get this error:
WARN query.JRJdbcQueryExecuter - The supplied java.sql.Connection object is null.
i only get a blank pdf file..
This is my method to export to PDF:
public void printReport(ActionEvent event) throws JRException, IOException {
String reportPath = FacesContext.getCurrentInstance().getExternalContext().getRealPath("/test.jrxml");
JasperReport report = JasperCompileManager.compileReport(reportPath);
JasperPrint jasperPrint = JasperFillManager.fillReport(report, new HashMap<String, String>());
HttpServletResponse httpServletResponse = (HttpServletResponse) FacesContext.getCurrentInstance().getExternalContext().getResponse();
httpServletResponse.addHeader("Content-disposition", "attachment; filename=report.pdf");
ServletOutputStream servletOutputStream = httpServletResponse.getOutputStream();
JasperExportManager.exportReportToPdfStream(jasperPrint, servletOutputStream);
FacesContext.getCurrentInstance().responseComplete();
}
I'm new with jasperreports so i'm a little lost.. do i have to specify the connection string to de database or what? and where should i add it.
BTW, i'm using JSF 2, intellij and maven.
thanks.
i solved my issue.. i had to specify a DB connection for my report!
Connection conn;
try {
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
conn = DriverManager.getConnection("jdbc:sqlserver://localhost:55334;databaseName=Frutemu;integratedSecurity=true","","");
} catch (SQLException ex) {
} catch (ClassNotFoundException ex) {
}
and then in this line add the connection:
JasperPrint jasperPrint = JasperFillManager.fillReport(report, new HashMap<String, String>(), conn);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With