Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- controller.RelatorioBean.getConexao null java.lang.ClassNotFoundException: "com.mysql.jdbc.Driver
- public class RelatorioBean {
- private HttpServletResponse response;
- private FacesContext context;
- private ByteArrayOutputStream baos;
- private InputStream stream;
- private Connection con;
- private List<Funcionario> funcionarios = this.listarDadosRel();
- private List<Funcionario> list;
- public List<Funcionario> getFuncionarios() {
- return funcionarios;
- }
- public List<Funcionario> listarDadosRel() {
- List<Funcionario> relatorio = new ArrayList<Funcionario>();
- String sqq = "SELECT * FROM funcionario "
- + "left join dadosprofissionais "
- + "ON funcionario.cpf=dadosprofissionais.cpf "
- + "order by funcionario.cpf;";
- try {
- Statement tt = Conexao.getConexao().createStatement();
- ResultSet resul = tt.executeQuery(sqq);
- while (resul.next()) {
- Funcionario funcionario = new Funcionario();
- funcionario.setCpf(resul.getString("cpf"));
- funcionario.setMatricula(resul.getInt("matricula"));
- funcionario.setNome(resul.getString("nome"));
- relatorio.add(funcionario);
- }
- } catch (SQLException ex) {
- Logger.getLogger(ControlerBean.class.getName()).log(Level.SEVERE, null, ex);
- }
- return relatorio;
- }
- public RelatorioBean() {
- this.context = FacesContext.getCurrentInstance();
- this.response = (HttpServletResponse) context.getExternalContext().getResponse();
- }
- public void exporterPdf() {
- stream = this.getClass().getResourceAsStream("/Ireport/ireport_1.jasper");
- Map<String, Object> params = new HashMap<String, Object>();
- baos = new ByteArrayOutputStream();
- try {
- JasperReport report = (JasperReport) JRLoader.loadObject(stream);
- **JasperPrint print = JasperFillManager.fillReport(report, params, getConexao());**
- JasperExportManager.exportReportToPdfStream(print, baos);
- response.reset();
- response.setContentType("application/pdf");
- response.setContentLength(baos.size());
- response.setHeader("Content-disposition", "inline; filename=relatorio.pdf");
- response.getOutputStream().write(baos.toByteArray());
- response.getOutputStream().flush();
- response.getOutputStream().close();
- context.responseComplete();
- } catch (JRException ex) {
- Logger.getLogger(RelatorioBean.class.getName()).log(Level.SEVERE, null, ex);
- } catch (IOException ex) {
- Logger.getLogger(RelatorioBean.class.getName()).log(Level.SEVERE, null, ex);
- }
- }
- public Connection getConexao() {
- try {
- **Class.forName("com.mysql.jdbc.Driver:");**
- con = DriverManager.getConnection("jdbc:mysql://localhost/dpd", "root", "root");
- return con;
- } catch (SQLException ex) {
- Logger.getLogger(RelatorioBean.class.getName()).log(Level.SEVERE, null, ex);
- } catch (ClassNotFoundException ex) {
- Logger.getLogger(RelatorioBean.class.getName()).log(Level.SEVERE, null, ex);
- }
- return con;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement