2005 IR Help Posted August 26, 2006 Share Posted August 26, 2006 By: spikeqc - spikeqc help with running the sample applications 2004-07-03 04:21 it compiles without errors but it produces the output: QueryApp usage tjava QueryApp -Ttask -Ffile tTasks : compile | fill1 | fill2 | fill3 | fill4 | print | pdf | xml | xmlEmbed | html | xls | csv | run here's my code: public static void main(String[] args) { String fileName = "-FQueryReport.jasper"; String taskName = "-Tprint"; if(args.length == 0) { usage(); return; } int k = 0; while ( args.length > k ) { if ( args[k].startsWith("-T") ) taskName = args[k].substring(2); if ( args[k].startsWith("-F") ) fileName = args[k].substring(2); k++; } try { long start = System.currentTimeMillis(); if (TASK_COMPILE.equals(taskName)) { JasperCompileManager.compileReportToFile(fileName); System.err.println("Compile time : " + (System.currentTimeMillis() - start)); System.exit(0); } else if (TASK_FILL.equals(taskName)) { //Preparing parameters Map parameters = new HashMap(); parameters.put("ReportTitle", "Address Report"); parameters.put("FilterClause", "'Boston', 'Chicago', 'Oslo'"); parameters.put("OrderClause", "City"); JasperFillManager.fillReportToFile(fileName, parameters, getConnection()); System.err.println("Filling time : " + (System.currentTimeMillis() - start)); System.exit(0); } else if (TASK_PRINT.equals(taskName)) { JasperPrintManager.printReport(fileName, true); System.err.println("Printing time : " + (System.currentTimeMillis() - start)); System.exit(0); } else if (TASK_PDF.equals(taskName)) { JasperExportManager.exportReportToPdfFile(fileName); System.err.println("PDF creation time : " + (System.currentTimeMillis() - start)); System.exit(0); } else if (TASK_XML.equals(taskName)) { JasperExportManager.exportReportToXmlFile(fileName, false); System.err.println("XML creation time : " + (System.currentTimeMillis() - start)); System.exit(0); } else if (TASK_XML_EMBED.equals(taskName)) { JasperExportManager.exportReportToXmlFile(fileName, true); System.err.println("XML creation time : " + (System.currentTimeMillis() - start)); System.exit(0); } else if (TASK_HTML.equals(taskName)) { JasperExportManager.exportReportToHtmlFile(fileName); System.err.println("HTML creation time : " + (System.currentTimeMillis() - start)); System.exit(0); } else if (TASK_XLS.equals(taskName)) { File sourceFile = new File(fileName); JasperPrint jasperPrint = (JasperPrint)JRLoader.loadObject(sourceFile); File destFile = new File(sourceFile.getParent(), jasperPrint.getName() + ".xls"); JRXlsExporter exporter = new JRXlsExporter(); exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint); exporter.setParameter(JRExporterParameter.OUTPUT_FILE_NAME, destFile.toString()); exporter.setParameter(JRXlsExporterParameter.IS_ONE_PAGE_PER_SHEET, Boolean.FALSE); exporter.exportReport(); System.err.println("XLS creation time : " + (System.currentTimeMillis() - start)); System.exit(0); } else if (TASK_CSV.equals(taskName)) { File sourceFile = new File(fileName); JasperPrint jasperPrint = (JasperPrint)JRLoader.loadObject(sourceFile); File destFile = new File(sourceFile.getParent(), jasperPrint.getName() + ".csv"); JRCsvExporter exporter = new JRCsvExporter(); exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint); exporter.setParameter(JRExporterParameter.OUTPUT_FILE_NAME, destFile.toString()); exporter.exportReport(); System.err.println("CSV creation time : " + (System.currentTimeMillis() - start)); System.exit(0); } else if (TASK_RUN.equals(taskName)) { //Preparing parameters Map parameters = new HashMap(); parameters.put("ReportTitle", "Address Report"); parameters.put("FilterClause", "'Boston', 'Chicago'"); parameters.put("OrderClause", "City,"); JasperRunManager.runReportToPdfFile(fileName, parameters, getConnection()); System.err.println("PDF running time : " + (System.currentTimeMillis() - start)); System.exit(0); } else { usage(); System.exit(0); } } catch (JRException e) { e.printStackTrace(); System.exit(1); } catch (Exception e) { e.printStackTrace(); System.exit(1); } } /** * */ private static void usage() { System.out.println( "QueryApp usage:" ); System.out.println( "tjava QueryApp -Ttask -Ffile" ); System.out.println( "tTasks : compile | fill1 | fill2 | fill3 | fill4 | print | pdf | xml | xmlEmbed | html | xls | csv | run" ); } /** * */ private static Connection getConnection() throws ClassNotFoundException, SQLException { //Change these settings according to your local configuration String driver = "com.mysql.jdbc.Driver"; String connectString = "jdbc:mysql://localhost/hsqldb"; String user = "root"; String password = ""; Class.forName(driver); Connection conn = DriverManager.getConnection(connectString, user, password); return conn; } I dont know how to run the program. Will somone please tell me how. I dont know if I supplied the right parameters for filename and taskname strings in the code. What's wrong with my code? Please help me... Thanks Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now