Jump to content
We've recently updated our Privacy Statement, available here ×

Showing image from database


mortoza

Recommended Posts

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

Link to comment
Share on other sites

  • Replies 15
  • Created
  • Last Reply

Top Posters In This Topic

Hi,

 

try declaring the field as object.

 

Code:
<field name="logo" class="java.lang.Object"/>

 

and cast it to byte[]

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

 

dont forget to import JRImageLoader

 

Code:
[code]<import value="net.sf.jasperreports.engine.util.JRImageLoader" />

 

regards,

 

midrag

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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)

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

@mortoza:

 

try replacing

Code:
<imageExpression class="java.awt.Image"><![CDATA[ $F{CompLogo}]]></imageExpression>

 

with

 

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

 

and dont forget to import the JRImageLoader

Code:
[code]<import value="net.sf.jasperreports.engine.util.JRImageLoader" />

 

you can modify the jrxml from iReport by clicking Edit -> XML Source

Link to comment
Share on other sites

  • 5 years later...

 

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>
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...