My impression report is only working in the local application, using connection with Hibernate, when I try to run on the server it does not work due to lack of connection to the database, how can I use a connection without being using Hibernate and that works in the Web Application?
Report.java
public void imprimirVenda() {
Map<String, Object> parametros = new HashMap<>();
FacesContext facesContext = FacesContext.getCurrentInstance();
HttpServletResponse response = (HttpServletResponse) facesContext.getExternalContext().getResponse();
RelatorioVenda executor = new RelatorioVenda("/impressao/imp_venda.jasper",
response, parametros, "Impressão da Venda.pdf", this.vendaMB.getVenda().getIdvenda());
Session session = manager.unwrap(Session.class);
session.doWork(executor);
facesContext.responseComplete();
}
RelatorioVenda.java
public class RelatorioVenda implements Work {
private final String caminhoRelatorio;
private final HttpServletResponse response;
private final Map<String, Object> parametros;
private final String nomeArquivoSaida;
private final Long id;
public RelatorioVenda(String caminhoRelatorio,
HttpServletResponse response, Map<String, Object> parametros,
String nomeArquivoSaida, Long id) {
this.caminhoRelatorio = caminhoRelatorio;
this.response = response;
this.parametros = parametros;
this.nomeArquivoSaida = nomeArquivoSaida;
this.id = id;
}
@Override
public void execute(Connection connection) throws SQLException {
try {
String relatorioStream = servlet.getRealPath(this.caminhoRelatorio);
parametros.put("idvenda", id );
JasperPrint print = JasperFillManager.fillReport(relatorioStream, this.parametros, connection);
Exporter<ExporterInput, PdfReportConfiguration, PdfExporterConfiguration, OutputStreamExporterOutput> exportador = new JRPdfExporter();
exportador.setExporterInput(new SimpleExporterInput(print));
exportador.setExporterOutput(new SimpleOutputStreamExporterOutput(response.getOutputStream()));
response.setContentType("application/pdf");
exportador.exportReport();
} catch (Exception e) {
throw new SQLException("Erro ao executar relatório ", e);
}
}
}
Someone helps me make another connection to the Database. Thanks in advance