我刚开始在 netbeans 7.0 中使用 ireports。我想知道如何通过单击按钮打开 ireport!谢谢
布赖恩
我可以给你一个示例代码。您必须在按钮单击事件中调用您的方法。
public void SuppInvoice(String supinvoice){
Connection conn=null;
try {
conn = Database.con();
JasperDesign jd = JRXmlLoader.load("src\\Reports\\report15.jrxml");
String sql = "select date,pName,name,supinvoice,qty,price from product p,stock s,supplier u where s.pid=p.pid and s.supid=u.supid and s.supinvoice='"+supinvoice+"'";
JRDesignQuery newQuery = new JRDesignQuery();
newQuery.setText(sql);
jd.setQuery(newQuery);
JasperReport jr = JasperCompileManager.compileReport(jd);
JasperPrint jp = JasperFillManager.fillReport(jr, null, conn);
JasperViewer.viewReport(jp, false);
} catch (ClassNotFoundException | SQLException | JRException e) {
JOptionPane.showMessageDialog(null, e);
e.printStackTrace();
}
}
如果您只想使用 iReports,则无需直接使用 netbeans 7.0。您可以从以下位置独立下载 iReports:http://jasperforge.org/website/ireportwebsite/IR%20Website/ir_download.html?header=project&target= ireport
否则在加载 netbeans 7.0 并安装 iReports 插件后,iReports 窗口将位于窗口菜单下。您应该能够打开它们并且您的文件继续工作。
请记住保持 iReport 和 JasperServer 版本号相同,以使生活更轻松。