Guest User

Untitled

a guest
Oct 19th, 2017
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.46 KB | None | 0 0
  1. /*
  2. * To change this template, choose Tools | Templates
  3. * and open the template in the editor.
  4. */
  5. package printpreview;
  6. import java.sql.*;
  7. import java.util.*;
  8. import javax.swing.JOptionPane;
  9. import net.sf.jasperreports.engine.*;
  10. import net.sf.jasperreports.engine.design.JasperDesign;
  11. import net.sf.jasperreports.engine.xml.JRXmlLoader;
  12. import net.sf.jasperreports.view.*;
  13. /**
  14. *
  15. * @author 3csb-16
  16. */
  17. public class PrintPreview2 {
  18. public PrintPreview2()
  19. {try{
  20. Class.forName("com.mysql.jdbc.Driver");
  21. Connection conn = DriverManager.getConnection("jdbc:mysql://localhost/my3csb","root","1234");
  22. String sn = JOptionPane.showInputDialog("Enter a Student Number");
  23. Map param = new HashMap();
  24. param.put("studnum", sn);
  25. param.put("user", "Jess Agbayani");
  26. String sourceDir = "D:\\jreport1.jrxml";
  27. String destinationDir = "D:\\jreport1.pdf";
  28. JasperDesign jd = JRXmlLoader.load(sourceDir);
  29. JasperReport jr = JasperCompileManager.compileReport(jd);
  30. JasperPrint jp = JasperFillManager.fillReport(jr, param,conn);
  31. JasperExportManager.exportReportToPdfFile(jp,destinationDir);
  32. JasperViewer.viewReport(jp,false);
  33. conn.close();
  34. }
  35. catch(Exception e){JOptionPane.showMessageDialog(null, e.getMessage());}
  36. }
  37. /**
  38. * @param args the command line arguments
  39. */
  40. public static void main(String[] args) {
  41. PrintPreview2 pv = new PrintPreview2();
  42. // TODO code application logic here
  43. }
  44. }
Add Comment
Please, Sign In to add comment