-2
這裏是我的代碼我有3個textfields和1個comboBox.I hava使用mysql數據庫和休眠 我可以創建一個碧玉報告(/home/webwerks/gitpro/Swing/src/report5.jrxml「)給這樣的路徑沒關係,但我已經設置了outfile(jasper report)的動態路徑,你可以看到jButton5ActionPerformed代碼,我可以給這樣的outfile的靜態路徑(JasperExportManager.exportReportToPdfFile(jasperPrint,「/ home/webwerks/report在這個地方我可以給動態路徑.PDF「)如何請幫我Swing應用程序桌面
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
if (evt.getSource() == jButton1) {
String s = jTextField1.getText();
String s1 = jTextField2.getText();
String s2 = jTextField3.getText();
String s4 = (String) jComboBox1.getSelectedItem();
Session session = HibernateUtil.getSessionFactory().openSession();
session.beginTransaction();
Performance performance = new Performance();
performance.setFirerating(s4);
performance.setSoundrating(s);
performance.setWidth(s1);
performance.setMaxheight(s2);
session.save(performance);
session.flush();
}
}
private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
if (evt.getSource() == jButton5) {
try {
Session session = HibernateUtil.getSessionFactory().openSession();
List l = ((org.hibernate.classic.Session) session).find("from Hibernate.Performance");
Map parameters = new HashMap();
InputStream input = new FileInputStream("/home/webwerks/gitpro/Swing/src/report5.jrxml");
JasperDesign jasperDesign = JRXmlLoader.load(input);
JasperReport jasperReport = JasperCompileManager.compileReport(jasperDesign);
JRBeanCollectionDataSource ds = new JRBeanCollectionDataSource(l);
JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, parameters, ds);
JasperExportManager.exportReportToPdfFile(jasperPrint, "/home/webwerks/report.pdf");
} catch (Exception e) {
}
}
}
非常感謝你.. – user1411799