Quantcast
Channel: General Failure - Programming
Viewing all articles
Browse latest Browse all 8

Jasperreports and PHP a success - kind of

$
0
0
  1.  Install iReport 3.6.0
  2. Do a report with it and let it compile the report and it's subreports for you. 
  3. Fetch jasperreports-project 3.6.0 and uncompress it
  4. Run ant jar at the root of uncompressed directory
  5. Copy every jar-file from both dist- and lib-subdirectories to /var/lib/tomcat5/shared/lib 
  6. Make sure that tomcat can read copied files 
  7. Copy your database jdbc class to same directory
  8. Restart tomcat
  9. Do a directory that tomcat can write and read from
  10. Copy your compiled jasper-reports (.jasper)-fiels to that directory

Here is an example that can produce pdf-report with subreports and parameters from Postgresql-database.

<?php

require_once('java/Java.inc');

// Get the database connection

$drv = new Java('org.postgresql.Driver');

$objDbm = java("java.sql.DriverManager");

$objDbConnect = $objDbm->getConnection("jdbc:postgresql://host/databasename", "user", "passwords");

// My report has one subreport and requires five parameters

// they are all STRINGS! I tried dates and timestamps but something chokes 


$company='1105366-9';

$toimpiste='kaikki';

$startDay="2009-08-01"

$endDay="2009-09-01"

//

// This is the directory tomcat needs to be able to write and read from

// it contains the compiled reports (.jasper-files)

//

$reportPath="/web/Pikkusisko2/raporttimallit/";


// Parameters are passed in java hashmap, one way to generate one is

// like this

$parameters=new Java("java.util.HashMap");


$parameters->put('pYritys',$company);

$parameters->put('pToimipiste',$toimipiste);

$parameters->put('SUBREPORT_DIR',$reportPath);

$parameters->put('pAlkupaiva',$startday);

$parameters->put('pLoppupaiva',$endday);


// Generate report pdf

$jasperRunManager = new Java("net.sf.jasperreports.engine.JasperRunManager");

$rep=$jasperRunManager->runReportToPdfFile("$reportPath/projektit2.jasper", $parameters, $objDbConnect); 

?>


Viewing all articles
Browse latest Browse all 8

Trending Articles