Meu relatório de impressão só está funcionando na aplicação local, usando conexão com Hibernate, quando tento rodar no servidor não funciona por falta de conexão com o banco de dados, como posso usar uma conexão sem ser usando a do Hibernate e que funcione na Aplicação Web?
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();
}
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);
}
}
Alguém me ajuda a fazer outra conexão com o Banco de Dados. Agradeço desde já