我寫了一個簡單的應用程序來從我的服務器上獲取命令。我決定能夠運行一些報告並在JasperViewer中顯示它們,然後從那裏決定是否打印或導出/保存爲其他格式。它工作正常,當我運行在的NetBeans項目,但一旦我編譯它,並將其發佈到我的服務器,運行報告,但我不能讓報告在JasperViewer打開。實際上,觀衆根本不會啓動。Java Web Start應用程序中的JasperReports
這裏是我的代碼:
try {
Connection con = DriverManager.getConnection(
"jdbc:mysql://MYDATABASE",
"MY_UN",
"MY_PW");
java.sql.Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery("SELECT `Product_ID` AS PRODUCT_ID, `Name` AS PRODUCT_DESCRIPTION, `Qty` AS QTY, `Price` AS PRICE_EACH_LINE, `Line_Total` AS LINE_TOTAL_LINE FROM `orderlines`;");
JRResultSetDataSource resultSetDataSource = new JRResultSetDataSource(rs);
final Map<String, Object> parameter = new HashMap<String, Object>();
parameter.put("DEALER_NAME", "TY JACOBS");
parameter.put("DEALER_STREET", "MY_ADDRESS");
parameter.put("DEALER_CITY_STATE_ZIP", "MY_CITY_STATE_ZIP");
parameter.put("DEALER_PHONE", "MY_PHONE_NUMBER");
ClassLoader classloader = getClass().getClassLoader();
InputStream url = null;
url = classloader.getResourceAsStream("OK/report3.jrxml");
JasperReport jasperReport = JasperCompileManager.compileReport(url);
JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, parameter, resultSetDataSource);
JasperViewer.viewReport(jasperPrint, false);
} catch (SQLException|JRException ex) {
Logger.getLogger(DbReportDSFill.class.getName()).log(Level.SEVERE, null, ex);
}
還有一兩件事,我可以在本地也沒有問題運行它。它似乎只是我發佈到服務器,我無法在JasperViewer得到報告。