How to Import a Image from Database


I need ti import a blob image from Oracle to ireport..
hw can i do this...

I've done following changes in XML code..
But im getting errors..

<imageExpression class="java.awt.Image"><![CDATA[JRImageLoader.loadImage((byte[])$F{IMAGE})]]></imageExpression>

<field name="IMAGE" class="java.lang.Object"/>

<import value="net.sf.jasperreports.engine.util.JRImageLoader" />

Im getting this error


Error filling print... Error evaluating expression :      Source text : $F{IMAGE} 
net.sf.jasperreports.engine.fill.JRExpressionEvalException: Error evaluating expression :      Source text : $F{IMAGE}      at net.sf.jasperreports.engine.fill.JREvaluator.evaluate(      at net.sf.jasperreports.engine.fill.JRCalculator.evaluate(      at net.sf.jasperreports.engine.fill.JRCalculator.evaluate(      at net.sf.jasperreports.engine.fill.JRFillElement.evaluateExpression( </td></tr></tbody></table><br><br>Post Edited by atharindhi at 09/23/2010 13:29
atharindhi's picture
Joined: Jul 20 2010 - 8:27pm
Last seen: 7 years 2 months ago

2 Answers:

try using the the sql Blob's getBytes(long pos, int length) method to get the byte[]
rmukkamalla's picture
Joined: Oct 23 2008 - 1:56pm
Last seen: 8 years 11 months ago



If you want to load the image yourself, then you can declare the field as beeing of type or java.sql.Blob.

But I suggest you simply declare the report field as being of type java.awt.Image and let JR load it for you.


You then make sure that the image element expression is also of type java.awt.Image.


I hope this helps.


teodord's picture
Joined: Jun 30 2006 - 9:00am
Last seen: 17 min 40 sec ago