Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this template, choose Tools | Templates
- * and open the template in the editor.
- */
- package printpreview;
- import java.sql.*;
- import java.util.*;
- import javax.swing.JOptionPane;
- import net.sf.jasperreports.engine.*;
- import net.sf.jasperreports.engine.design.JasperDesign;
- import net.sf.jasperreports.engine.xml.JRXmlLoader;
- import net.sf.jasperreports.view.*;
- /**
- *
- * @author 3csb-16
- */
- public class PrintPreview2 {
- public PrintPreview2()
- {try{
- Class.forName("com.mysql.jdbc.Driver");
- Connection conn = DriverManager.getConnection("jdbc:mysql://localhost/my3csb","root","1234");
- String sn = JOptionPane.showInputDialog("Enter a Student Number");
- Map param = new HashMap();
- param.put("studnum", sn);
- param.put("user", "Jess Agbayani");
- String sourceDir = "D:\\jreport1.jrxml";
- String destinationDir = "D:\\jreport1.pdf";
- JasperDesign jd = JRXmlLoader.load(sourceDir);
- JasperReport jr = JasperCompileManager.compileReport(jd);
- JasperPrint jp = JasperFillManager.fillReport(jr, param,conn);
- JasperExportManager.exportReportToPdfFile(jp,destinationDir);
- JasperViewer.viewReport(jp,false);
- conn.close();
- }
- catch(Exception e){JOptionPane.showMessageDialog(null, e.getMessage());}
- }
- /**
- * @param args the command line arguments
- */
- public static void main(String[] args) {
- PrintPreview2 pv = new PrintPreview2();
- // TODO code application logic here
- }
- }
Add Comment
Please, Sign In to add comment