Jump to content
We've recently updated our Privacy Statement, available here ×

Slow report


VMASTER

Recommended Posts

Hi,

 

Firstly excuse my poor English. :(

 

to create reports i use the following code java:

 

Code:
public static void runReport(String databaseName, String userName, String password,String reportFile,String empID) {


try{
String report = reportFile;

HashMap reportParam = new HashMap();
reportParam.put("EMPID", empID);


Connection jdbcConnection = connectDB(databaseName, userName, password);
JasperPrint jasperPrint2 = JasperFillManager.fillReport(report, reportParam, jdbcConnection);


int lar = (int) Toolkit.getDefaultToolkit().getScreenSize().getWidth();
int alt = (int) Toolkit.getDefaultToolkit().getScreenSize().getHeight();
JRViewer jrv = new JRViewer(jasperPrint2);
jrv.setPreferredSize(new Dimension(lar - 50, alt - 50));
JScrollPane reportScroll = new JScrollPane(jrv);
JPanel viewer = new JPanel();
viewer.add(reportScroll);
JFrame finestra = new JFrame();
finestra.add(viewer);
finestra.pack();
finestra.setVisible(true);
finestra.repaint();


}catch(Exception ex) {
String connectMsg = "Could not create the report " + ex.getMessage() + "n " + ex.toString()+"n"+ex.getCause()+"n"+ex.fillInStackTrace();
System.out.println(connectMsg);
}

}



public static void main(String[] args) {

String databaseName = "xxx" ;
String userName = "xxx";
String password = "xxx";
String reportFile = "classic.jasper";
String str="";
/*
inserisco gli id da stampare dato che su classic.jasper l'interrogazione sql è del tipo :
select * from tabella where id in (str)
*/
runReport(databaseName, userName, password, reportFile,str);

return;

}

 

 

the problems are two:

1) a long time, when charging 24k record employs 1 minute and 6 seconds

2) java heap space, not work when charghe over 30k record because exhausts memory

 

 

how can solve these two problems? there is a way for fast uploading and viewing of data?

 

finally how can customize the jrviewer? for example, I would like to remove the button "save"

Link to comment
Share on other sites

  • Replies 5
  • Created
  • Last Reply

Top Posters In This Topic

You use one of the JR Virtualizers to prevent the heap from running out of memory when the report is filling.

 

http://jasperreports.sourceforge.net/api/net/sf/jasperreports/engine/fill/JRAbstractLRUVirtualizer.html

 

This will however make your report slower, but at least it will finish when over 30k:

 

Code:

// creating the virtualizer
JRFileVirtualizer virtualizer = new JRFileVirtualizer(200, "tmp"«»);

// filling the report
JasperPrint jasperPrint = fillReport(fileName, ds, virtualizer);

 

As for making the report faster if you are using a lot of subreports you might try reducing their usage as they can be expensive.

 

Other than that, how fast does your query run outside of JR? If it is taking a minute on its own I think this is where you need to focus your optimization efforts.

 

HTH

Link to comment
Share on other sites

thanks for your reply.

 

but I do not understand the argument "ds" is a datasource? or destination file?

 

In any case the problem is to find a faster way to perform the following statement:

Code:

JasperPrint jasperPrint2 = JasperFillManager.fillReport(report, reportParam, jdbcConnection);

 

suggestions?

Link to comment
Share on other sites

Sorry I left out some of the code sample.

 

Code:

private static JasperPrint fillReport(String fileName, JRDataSource dataSource, JRFileVirtualizer virtualizer) throws JRException
{
long start = System.currentTimeMillis();

// Preparing parameters
Map parameters = new HashMap();
parameters.put(JRParameter.REPORT_VIRTUALIZER, virtualizer);

JasperPrint jasperPrint = JasperFillManager.fillReport(fileName, parameters, dataSource);

virtualizer.setReadOnly(true);

System.err.println("Filling time : " + (System.currentTimeMillis() - start));
return jasperPrint;
}

 

BTW, this was obtained from the demo/samples/virtualizer folder of the JR source.

 

As for the speed, how fast does the query of the report run when you run it outside of the report on the same connection?

Link to comment
Share on other sites

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...