2013-06-19 11 views
5

im cercando di esportare un file jrxml in pdf, ma ottengo questo errore:L'oggetto java.sql.Connection in dotazione è nullo

WARN query.JRJdbcQueryExecuter - The supplied java.sql.Connection object is null. 

Ho solo ottenere un file PDF vuoto ..

Questo è il mio metodo di esportare in 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(); 
    } 

sono nuovo con jasperreports quindi sono un po 'perso .. devo specificare la stringa di connessione a de database o che cosa? e dove dovrei aggiungerlo.

BTW, sto usando JSF 2, intellij e maven.

grazie.

risposta

9

ho risolto il problema .. ho dovuto specificare una connessione DB per il mio rapporto!

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) { 

     } 

e quindi in questa linea aggiungere la connessione:

JasperPrint jasperPrint = JasperFillManager.fillReport(report, new HashMap<String, String>(), conn); 
+0

Grazie. Funziona :) –

Problemi correlati