Jasper report only works in the local application, does not work on the Web Server

Asked

Viewed 304 times

0

My print report is only working in the local application, using Hibernate connection, when I try to run on the server does not work due to lack of connection to the database, how can I use a connection without using the Hibernate and that works in the Web Application?

Reporteriomb.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();
}

Reporteriovenda.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. I thank you already

  • 1

    Friend your problem is connecting to the bank the problem is not in the report, you need to analyze your classes that generate the connection, put the connection class ai, such as url you use to connect to the database

  • This is the problem that I am unable to solve, trying to make a connection, passing the url, user and password, but giving error

  • 1

    If you don’t add your connection class it is difficult to help you. In my view Voce is clicking on the server application the url of the local database on your machine and not the database on the server, so I wanted to see your connection class

  • I solved the problem with this bank connection. public Connection getConnection() throws ClassNotFoundException {&#xA; try {&#xA; Class.forName("com.mysql.jdbc.Driver");&#xA; System.out.println("Conectando ao banco");&#xA; return DriverManager.getConnection("jdbc:mysql://localhost:3306/teste", "root", "123");&#xA; } catch (SQLException e) {&#xA; System.out.println("Não conectado");&#xA; throw new RuntimeException(e);&#xA; }&#xA; } .

  • After all what was the problem? I am seeing q the URL is still from a local PC and not from a server

  • But it served so

Show 1 more comment
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.