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
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
spending nearly one day, finally found the solution;
select convert(your_image,'base64') as img from yourtable
java.io.InputStream
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.
Displaying Image from blob (postgresql) to Image in iReport
In Postgresql image is stored as blob-oid
Code inside ReportController