Showing image from database

Hello
I want my company logo to be retrieved from databse (BLOB) and displayed in the report. When I want to display, I do not see any datatype like Blob or Object. As a result getting error message telling Blob datatype can not be mapped with ....

Can anyone help guiding me to the right direction in order to get the image from database and show in the jasperreport using iReport?

Regards,
Mortoza
Post edited by: mortoza, at: 2006/10/28 11:00
mortoza's picture
1186
Joined: Oct 13 2006 - 1:42pm
Last seen: 1 year 1 month ago

15 Answers:

what database are you using, I have done it with oracle, mysql.
tlavalle's picture
178
Joined: Oct 6 2006 - 9:48am
Last seen: 16 years 8 months ago
Hi Tlavalle
I am using mySQL database. Can you help me?
Regards,
Mortoza
mortoza's picture
1186
Joined: Oct 13 2006 - 1:42pm
Last seen: 1 year 1 month ago
i have a same problem too. :(
do you find any answer? :whistle:
greenday_ra's picture
Joined: Nov 4 2006 - 4:26pm
Last seen: 6 years 8 months ago
Hi,

try declaring the field as object.

Code:
<field name="logo" class="java.lang.Object"/></td></tr></tbody></table><br />
<br />
and cast it to byte[]<br />
<table align="center" border="0" cellpadding="3" cellspacing="1" width="90%"><tbody><tr><td><b>Code:</b></td></tr><tr><td><pre><imageExpression class="java.awt.Image"><![CDATA[JRImageLoader.loadImage((byte[])$F{logo})]]></imageExpression></td></tr></tbody></table><br />
<br />
dont forget to import JRImageLoader<br />
<br />
<table align="center" border="0" cellpadding="3" cellspacing="1" width="90%"><tbody><tr><td><b>Code:</b></td></tr><tr><td><pre><import value="net.sf.jasperreports.engine.util.JRImageLoader" /></td></tr></tbody></table><br />
<br />
regards,<br />
<br />
midrag
midrag's picture
1129
Joined: Oct 24 2006 - 11:39pm
Last seen: 16 years 7 months ago
Hi Midrag
Can you tel me how do I do this using iReport? I am not habituated in using the codes! Thanks in advance for the help.
Mortoza
mortoza's picture
1186
Joined: Oct 13 2006 - 1:42pm
Last seen: 1 year 1 month ago
Hi Midrag
I tried using iReport, its copiles well but when I run, get the following errors-

ÂFilling report...
ÂLocale: English (United States)
ÂTime zone: default
ErrorÂfillingÂprint...
java.lang.ClassCastException:Â[BÂcannotÂbeÂcastÂtoÂjava.awt.Image ÂÂÂÂatÂTest_1162930011531_354843.evaluate(Test_1162930011531_354843:163)Â

Can you help where is the problem?
Mortoza
mortoza's picture
1186
Joined: Oct 13 2006 - 1:42pm
Last seen: 1 year 1 month ago
Try to declare your field as java.awt.Image and the JDBC data source will attempt to create an image out of the Blob data.

HTH,
Lucian
lucianc's picture
77046
Joined: Jul 17 2006 - 1:10am
Last seen: 29 sec ago
mortoza wrote:
Hi Midrag
I tried using iReport, its copiles well but when I run, get the following errors-

ÂFilling report...
ÂLocale: English (United States)
ÂTime zone: default
ErrorÂfillingÂprint...
java.lang.ClassCastException:Â[BÂcannotÂbeÂcastÂtoÂjava.awt.Image ÂÂÂÂatÂTest_1162930011531_354843.evaluate(Test_1162930011531_354843:163)Â

Can you help where is the problem?
Mortoza


Plz post your jrxml (specially the part where using the image)
midrag's picture
1129
Joined: Oct 24 2006 - 11:39pm
Last seen: 16 years 7 months ago
Hi
I am attaching my .jrxml file for reference.

Thanks in advance for the help.
Regards,
Mortoza [file name=Test.jrxml size=5705]http://www.jasperforge.org/components/com_joomlaboard/uploaded/files/Tes...
mortoza's picture
1186
Joined: Oct 13 2006 - 1:42pm
Last seen: 1 year 1 month ago
I have had some success using an url from my database (MS SQL).

Basically, I insert the image into the report and in the Image Expression box I put:

"http://directory/subdirectory/image_file_name.jpg"


You have to include the expression in "" or you will get an error message. So if you can directly reference the path to your logo this might work for you.

The Image Expression Class should be:
java.lang.String

I was trying to use this technique for getting student pics to appear on various reports. I had some success but I encountered errors when the student didn't have a pic in the database. Since you are trying to bring in only one pic this might work.

I am sorry if this isn't the solution to your problem. I am pretty amateur at this. You might say that I am one of the monkeys at the typewriter hoping to write Shakespeare.
roetpag's picture
152
Joined: Nov 2 2006 - 4:27am
Last seen: 16 years 7 months ago
@mortoza:

try replacing
Code:
<imageExpression class="java.awt.Image"><![CDATA[ $F{CompLogo}]]></imageExpression></td></tr></tbody></table><br />
<br />
with<br />
<br />
<table align="center" border="0" cellpadding="3" cellspacing="1" width="90%"><tbody><tr><td><b>Code:</b></td></tr><tr><td><pre><imageExpression class="java.awt.Image"><![CDATA[JRImageLoader.loadImage((byte[])$F{CompLogo})]]></imageExpression></td></tr></tbody></table><br />
<br />
and dont forget to import the JRImageLoader<br />
<table align="center" border="0" cellpadding="3" cellspacing="1" width="90%"><tbody><tr><td><b>Code:</b></td></tr><tr><td><pre><import value="net.sf.jasperreports.engine.util.JRImageLoader" /></td></tr></tbody></table><br />
<br />
you can modify the jrxml from iReport by clicking Edit -> XML Source
midrag's picture
1129
Joined: Oct 24 2006 - 11:39pm
Last seen: 16 years 7 months ago
Hi
Can I edit this in iReport instead of writing in the xml file directly? If yes, how?

Regards,
Mortoza
mortoza's picture
1186
Joined: Oct 13 2006 - 1:42pm
Last seen: 1 year 1 month ago
double click on image -> image -> image expression

enter: JRImageLoader.loadImage((byte[])$F{CompLogo})

importing JRImageLoader:

edit -> report Import directives -> add -> net.sf.jasperreports.engine.util.JRImageLoader
midrag's picture
1129
Joined: Oct 24 2006 - 11:39pm
Last seen: 16 years 7 months ago
Hi Midrag,
Brilliant! It works. Thank you very very much.
Mortoza
mortoza's picture
1186
Joined: Oct 13 2006 - 1:42pm
Last seen: 1 year 1 month ago

 

hello, here i want display image from database on jasper,

for that i am using 

but image is not coming  on complilation of jasper,

so please guide for this, 

 

 

Code:
<imageExpression>
 
<![CDATA[JRImageLoader.loadImage((byte[])$F{membersdetails_AuthorizedRepSignature})]]>
 
</imageExpression></td></tr></tbody></table>
manishg440's picture
Joined: Apr 25 2012 - 8:10pm
Last seen: 11 years 1 month ago
Feedback
randomness