Revision history [back]

click to hide/show revision 1
initial version

answered 2012-07-13 21:41:33 +0800

marcelodecampos gravatar image marcelodecampos

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 );
    }
Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More