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
| void etat(String xo) {
int x = 0;
// - Paramètres de connexion à la base de données
String url = "jdbc:mysql://localhost/echeque";
String login = "echeque";
String password = "echeque";
Connection connection = null;
try {
// - Connexion à la base
Driver monDriver = new com.mysql.jdbc.Driver();
DriverManager.registerDriver(monDriver);
connection = (Connection) DriverManager.getConnection(url, login, password);
JasperDesign jasperDesign = JRXmlLoader.load(getClass().getResourceAsStream("\\Etat.jrxml"));;
JasperReport jasperReport = JasperCompileManager.compileReport(jasperDesign);
// - Paramètres à envoyer au rapport
Map parameters = new HashMap();
parameters.put("Date_Param", xo);
// - Execution du rapport
JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, parameters, connection);
// - Création du rapport au format PDF
JasperExportManager.exportReportToPdfFile(jasperPrint, "\\Etat.pdf");
JasperViewer.viewReport(jasperPrint, false);
} catch (JRException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
} finally {
try {
connection.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
} |
Partager