Displaying image in Ireports using PostgreSql

前端 未结 3 1468
鱼传尺愫
鱼传尺愫 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: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.

提交回复
热议问题