Display image in table from mysql database

Dear All,

I need to display images stored in mysql table as a blob data type into a table.

I followed
Henry Sara’s instructions
but i dont know what i am missing.

Can somebody help me, if possible pls. give some sample code to display images in table from mysql database.

A quick response is highly awaited.

Regards,

GlobalNeel

I don’t work with MySQL, but here is the code I use for getting images out of PostgreSQL (stored as bytea, which is pretty much the same as BLOB in MySQL).
You should be able to use this without any modifications.

For the generated cell below, I display either the entity’s name, or a picture of it is available.
In my case every Entity object is wrapped into an EntityWrapper in order to display data properly and enable proper sorting. This has no impact on the image generation code, of course.

If anyone has comments on how to make the code better, this will be much appreciated. But it works perfectly as-is.

addGeneratedColumn(“entityName”, new ColumnGenerator() {
@Override
public Component generateCell(Table table, Object itemId, Object columnId) {
EntityWrapper item = (EntityWrapper) itemId;
Component component;
Entity entity = item.getEntityData();
final byte img = entity.getImg();
String name = entity.getEntityName();
if (img == null) {
component = new Label(name);
} else {
StreamResource.StreamSource imageSource = new StreamResource.StreamSource() {
@Override
public InputStream getStream() {
return new ByteArrayInputStream(img);
}
};
StreamResource imageResource = new StreamResource(imageSource, name + “.png”, getApplication());
imageResource.setCacheTime(0);
Embedded image = new Embedded(name, imageResource);
image.requestRepaint();
SimpleDateFormat df = new SimpleDateFormat(“yyyyMMddHHmmssSSS”);
String filename = name + df.format(new Date()) + “.png”;
imageResource.setFilename(filename);
component = image;
}
return component;
}
});

Hi Valentin,

Thank you for the sample code.

Regards,

GlobalNeel