From: <php...@li...> - 2010-06-19 19:12:37
|
Hi, so you are running a Java desktop application and use the bridge to invoke > methods of your desktop app? > Not exactly; there is no desktop application per se. The code that opens the JDBC connection and generates the report, using PHP and the bridge, is as follows: try { $params = report_parse_post_parameters(); // Load the PostgreSQL database driver. // java( 'java.lang.Class' )->forName( 'org.postgresql.Driver' ); // Attempt a database connection. // $conn = java( 'java.sql.DriverManager' )->getConnection( "jdbc:postgresql://$dbhost/$dbname?user=$dbuser&password=$dbpass" ); // Use the fill manager to produce the report. // $fm = java('net.sf.jasperreports.engine.JasperFillManager'); $pm = $fm->fillReport($report, $params, $conn); header('Cache-Control: private'); header('Content-Description: File Transfer'); header("Content-Disposition: attachment, filename=$filename.pdf"); header('Content-Type: application/pdf'); header('Content-Transfer-Encoding: binary'); java_set_file_encoding('ISO-8859-1'); $em = java('net.sf.jasperreports.engine.JasperExportManager'); $result = $em->exportReportToPdf($pm); $conn->close(); header('Content-Length: ' . strlen( $result ) ); echo $result; } The JasperReports library is on the classpath when the bridge is started. I was trying to keep the *$conn* variable open for the next request. But that would probably lead to all kinds of nasty business. I suppose could add a connection pool and serialize that, instead. When I get a bit more time, I'll try it. Thanks, Peter. Dave |