Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Connection conn = null;
- try {
- try {
- Class.forName("com.mysql.jdbc.Driver");
- } catch (ClassNotFoundException e) {
- System.out.println("Please include Classpath Where your MySQL Driver is located");
- e.printStackTrace();
- }
- conn = DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/jwayma_tax2","student","student");
- if (conn != null)
- {
- System.out.println("Database Connected");
- } else
- {
- System.out.println(" connection Failed ");
- }
- //Parameters as Map to be passed to Jasper
- HashMap<String,Object> hmParams=new HashMap<String,Object>();
- hmParams.put("dec_id", new Integer(id));
- InputStream paiementReportStream= getClass().getResourceAsStream("Jasper/Paiement_db.jrxml");
- JasperReport jasperReport= JasperCompileManager.compileReport(paiementReportStream);
- JRSaver.saveObject(jasperReport, "Paiement_db.jasper");
- JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, hmParams, conn);
- JRPdfExporter exporter = new JRPdfExporter();
- exporter.setExporterInput(new SimpleExporterInput(jasperPrint));
- SimpleOutputStreamExporterOutput out =new SimpleOutputStreamExporterOutput("Paiement_db.pdf");
- exporter.setExporterOutput(out);
- SimplePdfReportConfiguration reportConfig= new SimplePdfReportConfiguration();
- reportConfig.setSizePageToContent(true);
- reportConfig.setForceLineBreakPolicy(false);
- SimplePdfExporterConfiguration exportConfig = new SimplePdfExporterConfiguration();
- exportConfig.setMetadataAuthor("baeldung");
- exportConfig.setEncrypted(true);
- exportConfig.setAllowedPermissionsHint("PRINTING");
- exporter.setConfiguration(reportConfig);
- exporter.setConfiguration(exportConfig);
- exporter.exportReport();
- } catch (Exception sqlExp) {
- System.out.printf("Exception::");
- sqlExp.printStackTrace();
- } finally {
- try {
- if (conn != null) {
- conn.close();
- conn = null;
- }
- } catch (SQLException expSQL) {
- System.out.println("SQLExp::CLOSING::" + expSQL.toString());
- }
- }
- String reportFileName = "Paiement_db";
- Connection conn = null;
- try {
- try {
- Class.forName("com.mysql.jdbc.Driver");
- } catch (ClassNotFoundException e) {
- System.out.println("Please include Classpath Where your MySQL Driver is located");
- e.printStackTrace();
- }
- conn = DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/jwayma_tax2","student","student");
- if (conn != null)
- {
- System.out.println("Database Connected");
- } else
- {
- System.out.println(" connection Failed ");
- }
- //Parameters as Map to be passed to Jasper
- HashMap<String,Object> hmParams=new HashMap<String,Object>();
- hmParams.put("dec_id", new Integer(id));
- JasperReport jasperReport = getCompiledFile(reportFileName, request);
- generateReportPDF(response, hmParams, jasperReport, conn);// For PDF report
- } catch (Exception sqlExp) {
- System.out.printf("Exception::");
- sqlExp.printStackTrace();
- } finally {
- try {
- if (conn != null) {
- conn.close();
- conn = null;
- }
- } catch (SQLException expSQL) {
- System.out.println("SQLExp::CLOSING::" + expSQL.toString());
- }
- }
- <?xml version="1.0" encoding="UTF-8"?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement