Links

   Quran Explorer - Interactive Audio Recitations & Translations

Thursday, February 28, 2013

Photos from DB to JasperReport

In my previous post i mentioned byte array datatype.
Its a simple(or is it simplistic) way of saving binary data into a db table. One example immediately comes to mind... yes photos!! "i want to save photos and render them in a printable report"

POSTGRES SQL

TABLE CREATE TABLE student(
student_id serial primary key,
reg_no varchar(7) not null,
photo bytea,
..
..
..
remarks text
);

The only field of interest is the photo field which is a byte array type

Most of the time i use iReport to design JasperReports and in this example I will use iReport 4.0

[[]]


Never mind.... the most important part is the ImageExpression class in the dynamic image.

Make sure its class is java.io.InputStream.

This may not be available in the iReport properties section so what u will do in such a case is click on the XML tab and type java.io.InputStream save then have fun coding

Migrating from PostgreSQL 8.3 to 9.0 and beyond - Byte Array perspective

My Nerd migos,

Its bn quite sometime since my last post.

I want to share my agonies (and help u avoid the same) when migrating applications from Postgres 8.3 (or below) to 9.0 and beyond. If you had/have tables with bytea then they will/may JUST stop working.

Some guy(s) with infinite wisdom decided to change the representation of byte array from the default (escape) to hex !!! I googled my head silly until i found a solution at stackoverflow.com (forgot the thread sorry!!!)

Ok straight to the solution. Export the 8.3 db (i prefer pg_dump --inserts dbname > /path/to/dumpfile.sql) then import (just use psql or ur favorite tool to run the script created by the pg_dump command).

The next thing is to change a configuration flag in postgresql.conf. Change bytea_output to 'escape' instead of the default 'hex'. restart the server and hug yourself.

"At least the postgres guy with infinite wisdom never forgot to add this flag for backward compatibility"

Plz dont ask me what is a bytea datatype. If u dont know it means u dont have it in ur DB so relax

Hope this helps