1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
| public void imprimerF(ActionEvent a) {
Connection conn = null;
String userName = "root";
String password = "";
String url = "jdbc:mysql://localhost:3306/mabase";
try {
Class.forName("com.mysql.jdbc.Driver").newInstance();
conn = DriverManager.getConnection(url, userName, password);
System.out.println("Database connection established");
JasperDesign jasperDesign = JRXmlLoader.load(getClass()
.getResourceAsStream("/rapports/fiche.jrxml"));
System.out.println("jrxml passé");
// - Paramètres à envoyer au rapport
Map parameters = new HashMap();
bar = (Bar) datable.getRowData();
codeB = bar.getIdBar();
parameters.put("codB", codeB);
String reportPath = "/rapports/fiche.jasper";
InputStream reportStream = getClass().getResourceAsStream(
reportPath);
JasperPrint jasperPrint = JasperFillManager.fillReport(
reportStream, parameters, conn);
System.out.println("jasper passé");
// - Création du rapport au format PDF
JasperExportManager.exportReportToPdfFile(jasperPrint,
"Fiche.pdf");
System.out.println("export pdf effectue");
Process p = Runtime.getRuntime().exec(
"rundll32 url.dll,FileProtocolHandler Fiche.pdf");
p.waitFor();
System.out.println("Done.");
} catch (InstantiationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalAccessException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (JRException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
} |
Partager