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

How can I use images in detail?


titan115

Recommended Posts

Hi,everyone,

I use jasperreport 3.5.1 in my project. I meet a problem  like this,I store my images in database,i want to display this images in detail,but images amount isn't fixed.How can I create my report template file,and assign images to the report?

Best regards.

Mxking

Link to comment
Share on other sites

  • Replies 2
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

Hi. I do it like this: I'm using JPA with Oracle, and the entity that has images has a java.awt.Image member, which is populated when the entity instance is loaded from the db. The property name is, say, "image". The template has a field for this property, named "image" (JPA data source expects the field names to correspond to entity property names), and an image element in the detail section. The expression class is set to java.awt.Image and the expression is simply "$F{image}". And this is all you have to do. You can of course set scaling and positioning, but this is specific to your app.

If you store the images in a BLOB and execute a JDBC query, you can feed the result set  to jasper or have the query incorporated into the template, and Jasper will use a javax.jdbc.Connection that you need to supply. The rest is pretty similar - the field has the same name as the column / alias you use in the query, the type is java.awt.Image, and the imge has the same properties set. Jasper automatically tries to transform BLOBs into images.

Hope this helps.

Link to comment
Share on other sites

jambalaya
Wrote:

Hi. I do it like this: I'm using JPA with Oracle, and the entity that has images has a java.awt.Image member, which is populated when the entity instance is loaded from the db. The property name is, say, "image". The template has a field for this property, named "image" (JPA data source expects the field names to correspond to entity property names), and an image element in the detail section. The expression class is set to java.awt.Image and the expression is simply "$F{image}". And this is all you have to do. You can of course set scaling and positioning, but this is specific to your app.

If you store the images in a BLOB and execute a JDBC query, you can feed the result set  to jasper or have the query incorporated into the template, and Jasper will use a javax.jdbc.Connection that you need to supply. The rest is pretty similar - the field has the same name as the column / alias you use in the query, the type is java.awt.Image, and the imge has the same properties set. Jasper automatically tries to transform BLOBs into images.

Hope this helps.

This is very useful for me.Thank you.But my app has a small difference to this you said.I use JRXMLDataSource,because the record in database cann't be used directly,I have to convert my database record to my report record.So there is problem how I pass my images to template?Maybe uses customized JRDataSource is a resolution.



Post Edited by titan115 at 07/24/2009 01:52
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...