Advertisement
Guest User

Untitled

a guest
Jul 28th, 2017
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.59 KB | None | 0 0
  1. Connection conn = null;
  2. try {
  3. try {
  4. Class.forName("com.mysql.jdbc.Driver");
  5. } catch (ClassNotFoundException e) {
  6. System.out.println("Please include Classpath Where your MySQL Driver is located");
  7. e.printStackTrace();
  8. }
  9. conn = DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/jwayma_tax2","student","student");
  10. if (conn != null)
  11. {
  12. System.out.println("Database Connected");
  13. } else
  14. {
  15. System.out.println(" connection Failed ");
  16. }
  17. //Parameters as Map to be passed to Jasper
  18. HashMap<String,Object> hmParams=new HashMap<String,Object>();
  19. hmParams.put("dec_id", new Integer(id));
  20. InputStream paiementReportStream= getClass().getResourceAsStream("Jasper/Paiement_db.jrxml");
  21. JasperReport jasperReport= JasperCompileManager.compileReport(paiementReportStream);
  22. JRSaver.saveObject(jasperReport, "Paiement_db.jasper");
  23. JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, hmParams, conn);
  24. JRPdfExporter exporter = new JRPdfExporter();
  25.  
  26. exporter.setExporterInput(new SimpleExporterInput(jasperPrint));
  27. SimpleOutputStreamExporterOutput out =new SimpleOutputStreamExporterOutput("Paiement_db.pdf");
  28. exporter.setExporterOutput(out);
  29.  
  30. SimplePdfReportConfiguration reportConfig= new SimplePdfReportConfiguration();
  31. reportConfig.setSizePageToContent(true);
  32. reportConfig.setForceLineBreakPolicy(false);
  33. SimplePdfExporterConfiguration exportConfig = new SimplePdfExporterConfiguration();
  34. exportConfig.setMetadataAuthor("baeldung");
  35. exportConfig.setEncrypted(true);
  36. exportConfig.setAllowedPermissionsHint("PRINTING");
  37. exporter.setConfiguration(reportConfig);
  38. exporter.setConfiguration(exportConfig);
  39. exporter.exportReport();
  40.  
  41. } catch (Exception sqlExp) {
  42. System.out.printf("Exception::");
  43. sqlExp.printStackTrace();
  44. } finally {
  45. try {
  46. if (conn != null) {
  47. conn.close();
  48. conn = null;
  49. }
  50. } catch (SQLException expSQL) {
  51. System.out.println("SQLExp::CLOSING::" + expSQL.toString());
  52. }
  53.  
  54. }
  55.  
  56. String reportFileName = "Paiement_db";
  57.  
  58. Connection conn = null;
  59. try {
  60. try {
  61. Class.forName("com.mysql.jdbc.Driver");
  62. } catch (ClassNotFoundException e) {
  63. System.out.println("Please include Classpath Where your MySQL Driver is located");
  64. e.printStackTrace();
  65. }
  66. conn = DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/jwayma_tax2","student","student");
  67. if (conn != null)
  68. {
  69. System.out.println("Database Connected");
  70. } else
  71. {
  72. System.out.println(" connection Failed ");
  73. }
  74. //Parameters as Map to be passed to Jasper
  75. HashMap<String,Object> hmParams=new HashMap<String,Object>();
  76. hmParams.put("dec_id", new Integer(id));
  77. JasperReport jasperReport = getCompiledFile(reportFileName, request);
  78. generateReportPDF(response, hmParams, jasperReport, conn);// For PDF report
  79.  
  80. } catch (Exception sqlExp) {
  81. System.out.printf("Exception::");
  82. sqlExp.printStackTrace();
  83. } finally {
  84. try {
  85. if (conn != null) {
  86. conn.close();
  87. conn = null;
  88. }
  89. } catch (SQLException expSQL) {
  90. System.out.println("SQLExp::CLOSING::" + expSQL.toString());
  91. }
  92.  
  93. }
  94.  
  95. <?xml version="1.0" encoding="UTF-8"?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement