-
FEATURED COMPONENTS
First time here? Check out the FAQ!
1 | initial version | |
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 );
}