Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The supplied java.sql.Connection object is null

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.

like image 221
user1462933 Avatar asked Jun 19 '13 05:06

user1462933


1 Answers

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);
like image 119
user1462933 Avatar answered Oct 11 '22 22:10

user1462933