Jasper Report
Code untuk Jasper Report yang biasa digunakan oleh programmer java untuk membuat laporan pada aplikasinya. berikut adalah kodenya
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
try {
// TODO add your handling code here:
Class.forName("com.mysql.jdbc.Driver");
Connection connection = DriverManager.getConnection("jdbc:mysql://localhost/senayandb", "root", "");
File file = new File("senayandb.jrxml");
File fileCompile = new File("senayandbsenayandb.jasper");
JasperCompileManager.compileReportToFile(
file.getAbsolutePath(),
fileCompile.getAbsolutePath());
File outputFile = new File("daftar_buku_" + (new Date().getTime()) + ".pdf");
File outputFileDocx = new File("daftar_buku.docx");
File outputFileXls = new File("daftar_buku.xlsx");
Map parameter = new HashMap();
parameter.put("isbn", "%" + isbn.getText() + "%");
parameter.put("judul", "%" + judul.getText() + "%");
FileOutputStream fos = new FileOutputStream(outputFile);
JasperPrint jasperPrint = JasperFillManager.fillReport(fileCompile.getAbsolutePath(), parameter, connection);
JRAbstractExporter exporter = new JRPdfExporter();
exporter.setParameter(JRXlsExporterParameter.JASPER_PRINT,
jasperPrint);
exporter.setParameter(JRXlsExporterParameter.OUTPUT_STREAM,
fos);
exporter.setParameter(JRExporterParameter.OUTPUT_FILE,
outputFile);
exporter.exportReport();
fos.close();
Process p = Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler "+outputFile.getAbsolutePath());
p.waitFor();
System.out.println("generate report to " + outputFile.getAbsolutePath());
} catch (Exception ex) {
Logger.getLogger(MainWindow.class.getName()).log(Level.SEVERE, null, ex);
}
}
JasperReport - Tutorial
4/
5
Oleh
Ichwanul Muslim