Jump to content
JasperReports Library 7.0 is now available ×

Help with running reports


2005 IR Help

Recommended Posts

By: spikeqc - spikeqc

Help with running reports

2004-07-02 00:30

I am new in using Jasperreports and I tried compiling on demo application, particularly QueryApp.java. The compilation is successful but when i try to run the program, it doesnt produce the report itself. Currenly I am using MySQL as my database. In the java file, I tried to change the parameters, database connection, and the .jasper file but still it wont work. I need help please ASAP. Thanks. I have a deadline in making the reports and its two days from now. If possible, i would appreciate it more if someone can give me a working application that can display a certain report in MySQL database. Thank you

 

 

 

 

By: C-Box - c-box

RE: Help with running reports

2004-07-02 02:06

What's the error output in console?

 

I don't use MySQL but be sure to have the connection established successfully. I guess you will have to copy the needed JAR-libs for MySQL-driver into the lib-directory of jasper-reports (so I had to do, with MS-SQL-Server JAR's)

 

If you use the same tables in your MySQL-Table it sould work. (I canged the HSQLDB-Sample towards MS-SQL-Server, and it worked)

 

hth

C-Box

 

 

 

 

By: spikeqc - spikeqc

RE: Help with running reports

2004-07-02 02:38

After setting up all the needed jar files, and making a replica of the database written in HSQLDB to MySQL, the java files in the demo folder would run already? How? By issuing the java command in the console?

 

 

 

 

By: C-Box - c-box

RE: Help with running reports

2004-07-02 05:13

Well actually you just have to replace the "getConnection" method in the query-sample (for example) to the MySQL specific lines.

 

private static Connection getConnection() throws ClassNotFoundException, SQLException

{

//Change these settings from HSQLDB according to your local configuration for example to MySQL

String driver = "org.hsqldb.jdbcDriver"; //Don't know how the MySQL-Driverstring should be, but I guess you know it.

String connectString = "jdbc:hsqldb:hsql://localhost";

String user = "sa";

String password = "";

 

 

Class.forName(driver);

Connection conn = DriverManager.getConnection(connectString, user, password);

return conn;

}

 

that should be enough. You have to recompile the java-file and than start the ant-tasks "compile" then "fill" and then "view"... that must work if you have the same table with the same fieldnames/types in your MySQL-Database! If not, than your "getConnectionMethod" should throw an exception.

 

hth

C-Box

 

 

 

 

By: spikeqc - spikeqc

RE: Help with running reports

2004-07-02 12:44

thanks for your help C-Box. I just want to know how to start the ant-tasks?

 

 

 

 

By: spikeqc - spikeqc

RE: Help with running reports

2004-07-02 12:52

I downloaded iReports and i tried designing .jasper files. Do I need to run the ant-tasks still on the java code? if yes, how? thanks for your help.. hopin for your urgent reply. thanks

 

 

 

 

By: spikeqc - spikeqc

RE: Help with running reports

2004-07-03 01:49

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;

}

 

What's wrong with my code? Please help me...

 

 

 

 

By: C-Box - c-box

RE: Help with running reports

2004-07-05 00:17

Well you have to install ANT and put it into your PATH to call it anywhere from commandline... then go to your directory from the modified sample and look for the "build.xml"... there are so called "targets" within.... (each target makes a different job)

 

make a new commandline from that dir and put

ant compile

 

the files should get recompiled....

 

then

 

ant fill

 

and the report XMLfile should get filled to a jrprint-file

 

then

 

ant view

 

and the JRViewer should appear...

 

hth

C-Box

Link to comment
Share on other sites

  • Replies 0
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Top Posters In This Topic

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 account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...