-
FEATURED COMPONENTS
First time here? Check out the FAQ!
Hi,
Is there any method to directly use JDBC Connection in jasperreport component because
query already defined within japer template , so that i can fill report ??
thanks in advance
Kamen Lai
You can pass a Connection objet to JasperReports JasperFillManager.
Check JasperReports API Docs http://jasperreports.sourceforge.net/api/index.html
Yes I know if I directly use JasperFillManager to genernate report and like in smalltalk document.
What I mean is use ZK Jasperreport component , there is oly JRDataSource property and no Connection object?
Thanks
I guess there is no copnnection usage inside Jasperreport component because it is already receving the data source. I think this is made to separate concers between JasperReports and ZK.
You could make write your own component that derivates from Jasperreport component and add connection objeto support.
I have set the connection to the template from composer. Report is generated correctly but I am seeing lot of db connections happening.
Doesn't zk jasper close the connection?
How can i close the connection explicitly if required? Because i see call to generate report is a non blocking call.
Thanks
-JE
if I understood your question, is this what you´re looking for?
protected JasperPrint compileReport( String report, Map<String, Object> params ) { if ( report == null ) { return null; } if ( params == null ) { params = new HashMap<String, Object>( ); } String realPath; realPath = getRealPath( "/img" ); params.put( "IMAGE_PATH", realPath ); try { realPath = getRealPath( report ); File file = new File( realPath ); String name = SysUtils.getExtension( file ); if ( SysUtils.isEmpty( name ) ) { name = realPath + ".jrxml"; } JasperReport jasperReport = JasperCompileManager.compileReport( name ); return JasperFillManager.fillReport( jasperReport, params, getConnection( ) ); } catch ( JRException e ) { logger.error( "JRException", e ); } catch ( SQLException e ) { logger.error( "JRException", e ); } catch ( ClassNotFoundException e ) { logger.error( "JRException", e ); } return null; } protected Connection getConnection( ) throws SQLException, ClassNotFoundException { Class.forName( "org.postgresql.Driver" ); String url = "jdbc:postgresql:database"; Properties props = new Properties( ); props.setProperty( "user", "user" ); props.setProperty( "password", "password" ); return DriverManager.getConnection( url, props ); }
After fulfilling your report, you don't need the connection anymore!
This is the corrected code.
protected JasperPrint compileReport( String report, Map<String, Object> params ) { if ( report == null ) { return null; } if ( params == null ) { params = new HashMap<String, Object>( ); } String realPath; realPath = getRealPath( "/img" ); params.put( "IMAGE_PATH", realPath ); Connection conn = null; try { realPath = getRealPath( report ); File file = new File( realPath ); String name = SysUtils.getExtension( file ); if ( SysUtils.isEmpty( name ) ) { name = realPath + ".jrxml"; } conn = getConnection( ); JasperReport jasperReport = JasperCompileManager.compileReport( name ); JasperPrint nRet = JasperFillManager.fillReport( jasperReport, params, conn ); return nRet; } catch( JRException e ) { logger.error( "JRException", e ); } catch( SQLException e ) { logger.error( "JRException", e ); } catch( ClassNotFoundException e ) { logger.error( "JRException", e ); } finally { try { if ( conn != null && conn.isClosed( ) == false ) { conn.close( ); conn = null; } } catch( SQLException e ) { e.printStackTrace( ); } } return null; }
Thank you marcelodecampos.
But I see here you are using JasperFillManager.fillReport(JasperReport jasperReport, java.util.Map<java.lang.String,java.lang.Object> parameters, java.sql.Connection connection)
Here In your code JasperReport is an instance of net.sf.jasperreports.engine.JapserReport.
But in my code I am using org.zkoss.zkex.zul .Jasperreport and i don't see connection.
And hence I continue to face this issue!!
And my code is based on http://www.zkoss.org/zkdemo/reporting/jasperreport
Asked: 2009-01-18 03:29:37 +0800
Seen: 794 times
Last updated: Jul 23 '12