tpbolon

Untitled

Dec 10th, 2017
80
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package ContohLaporan;
  2.  
  3. import java.io.File;
  4. import java.sql.Connection;
  5. import java.sql.DriverManager;
  6. import java.util.HashMap;
  7. import java.util.Map;
  8. import javax.swing.JOptionPane;
  9. import net.sf.jasperreports.engine.JasperCompileManager;
  10. import net.sf.jasperreports.engine.JasperFillManager;
  11. import net.sf.jasperreports.engine.JasperPrint;
  12. import net.sf.jasperreports.engine.JasperReport;
  13. import net.sf.jasperreports.engine.design.JasperDesign;
  14. import net.sf.jasperreports.engine.xml.JRXmlLoader;
  15. import net.sf.jasperreports.view.JasperViewer;
  16.  
  17. public class menulaporan extends javax.swing.JFrame {
  18.  
  19. private Connection con;
  20.     public menulaporan() {
  21.         initComponents();
  22.     }
  23.     private void jMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) {                                          
  24.         // TODO add your handling code here:
  25.         JasperReport jasRep;
  26.         JasperPrint jasPri;
  27.         Map<String, Object> kode = new HashMap<String, Object>();
  28.         //Map<String, Object> kode=new HashMap<>();
  29.         JasperDesign jasDes;
  30.         try {
  31.             Class.forName("com.mysql.jdbc.Driver");
  32.             con = DriverManager.getConnection
  33.                 ("jdbc:mysql://localhost:3306/db_supermarket_siti3", "root", "");
  34.             String filename = System.getProperty("user.dir") + "/src/ContohLaporan/report3.jrxml";
  35.             File report = new File(filename);
  36.             jasDes = JRXmlLoader.load(report);
  37.             kode.clear();
  38.             jasRep = JasperCompileManager.compileReport(jasDes);
  39.             jasPri = JasperFillManager.fillReport(jasRep, kode, con);
  40.             JasperViewer.viewReport(jasPri, false);
  41.         } catch (Exception e) {
  42.             JOptionPane.showMessageDialog(null,
  43.                     "Gagal Menampilkan Laporan: \n"+ e.getMessage());
  44.             //System.out.println(e.getMessage());
  45.         }
  46.     }  
  47. }
RAW Paste Data