Displaying image in Ireports using PostgreSql

前端 未结 3 1466
鱼传尺愫
鱼传尺愫 2020-12-04 02:29

I am trying to load image from PostgreSQL database into jaspersoft ireports(4.0) but I am receiving an error.

In PostgreSQL image is stored as bytea object. In irepo

相关标签:
3条回答
  • 2020-12-04 02:39

    In PostgreSQL the bytea type is not a BLOB, and you can't use a stream. In SQL standard terms it is a byte string. It should be loaded to a byte array in Java.

    If you want to use BLOB techniques in PostgreSQL you must use the large objects feature.

    http://www.postgresql.org/docs/current/interactive/largeobjects.html

    0 讨论(0)
  • 2020-12-04 02:54

    spending nearly one day, finally found the solution;

    1. in sql query select convert(your_image,'base64') as img from yourtable
    2. set image expression class to java.io.InputStream
    3. in image expression net.sf.jasperreports.engine.util.JRImageLoader.getInstance(new SimpleJasperReportsContext()).loadAwtImageFromBytes(javax.xml.bind.DatatypeConverter.parseBase64Binary($F{img}))

    EDIT:

    My Postgresql version is : 9.4,

    Thanks to FiruzzZ he stated that in postgresql 9.1 instead of convert function, encode(bytea,'base64') is available.

    0 讨论(0)
  • 2020-12-04 03:05

    Displaying Image from blob (postgresql) to Image in iReport

    In Postgresql image is stored as blob-oid
    Code inside ReportController

    1. fetch that oid string from database convert it into byte
    2. convert byte array value in InputStream value
    3. map it to the parameter that will be used inside iReport
    4. take one Image element change its type to java.io.InputStream
    5. Create one parameter of type java.io.InputStream (use the same name as mapped inside ReportController)
    6. Now Build project and Run
    0 讨论(0)
提交回复
热议问题