Suivre ce blog
Administration Créer mon blog
1 octobre 2006 7 01 /10 /octobre /2006 11:15


Here is a Java Bean that allows to read, display and write images.

(See the last evolution of this solution here

When you load an image within Forms with the Read_Image_File() built-in, you can notice a certain lack of quality, both in the Forms Image item display quality and in the real information stored in the blob column.
The image seems to be compressed before it is stored in the database. This compression rate is between 25 and 50% !
This Java Bean allows to load images from a file, then store them in the database.

The Forms sample dialog provided with the article uses two image rooms:

 - The first one is a standard Forms Image item that is populated with the Client_Image.Read_Image_File() Webutil function that populates the PHOTO blob column.

 - The second one is the Java Bean itself that populates the PHOTO_JAVA blob column.

As you see as follows, the Read_Image_File() function can drastically compress the initial image:

1 select
2 identifiant,
3 length(photo),
4 length(photo_java),
5 round((length(photo)/length(photo_java)*100),1) || '%' "photo reduction"
6 from photos
7* where photo is not null
SQL> /

----------- ------------- ------------------ ---------------
2           23536         100952             23.3%
1            6763          13548             49.9%

This JavaBean connect to the database through the JDBC driver to read and write the images.
Of course, some of you can complain that this solution needs a second connection, the loading of the classes12.jar file on the client machine, so it is "deconnected" from the Forms transaction.
For this very moment, my answer is : everything has its price, and if you need to keep and display the real quality of the images in your Forms application, this bean is the one you need.

Let's see the screenshot to decide !

handleimage small format

Click here to get the full format image

The Java code

The implementation class of the Bean Item


The methods you can call

Set the connection string


e.g. :
Set_Custom_Property( 'BL.BEAN', 1, '
SETCONN', 'jdbc:oracle:thin:@my-machine:1521:XE' ) ;   
(Provide the complete jdbc:oracle:thin:... syntax)

Set the username


Set the password


Set the
database image table information


p1 is the table name that hold the image blob column
p2 is the column name that hold the image
p3 is the column name that identifies the unique row in the table (for the UPDATE statment)


The instruction above indicates that the PHOTOS table handle images in the PHOTO_JAVA blob column, and the key column that identifies the unique row is IDENTIFIANT.

Read an image from a local file


Set_Custom_Property( 'BLZ.BEAN', 1, 'READIMGFILE', 'D:/image.jpg' ) ; 

Read an image from the database table


Set_Custom_Property( 'BLZ.BEAN', 1, 'READIMGBASE', '1' ) ; 

unique_ID is the value to identify a unique row to update in the table. The above instruction will be interpreted as :


Put this method into the When-New-Record-Instance block-level trigger

Write an image to the database table


Set_Custom_Property( 'BLZ.BEAN', 1, 'WRITEIMGBASE', '1' ) ; 

unique_ID is the value to identify a unique row to update in the table.
The above instruction will be interpreted as :


Put this method into the Post-Insert and Post-Update block-level triggers

Clear the image

Set_Custom_Property( 'BL.BEAN', 1, '
CLEAR' , '' ) ;

This function has to be called in a When-New-Record-Instance trigger if the record does not exist:

When-New-Record-Instance trigger:
If :PHOTOS.IDENTIFIANT is not null Then
   Set_Custom_Property( 'BLZ.BEAN', 1, 'READIMGBASE', :PHOTOS.IDENTIFIANT ) ;
   Set_Custom_Property( 'BLZ.BEAN', 1, 'CLEAR', '' ) ;
End if ;
:BLZ.IMG_SIZE := Get_Custom_Property( 'BLZ.BEAN', 1, 'GETSIZE' ) ;

Set the log mode to output the Bean messages

Set_Custom_Property( 'BL
.BEAN', 1, 'SETLOG' , 'true|false' ) ;

Set mode to allow the display of the scrollbars if needed

Set_Custom_Property( 'BL.BEAN', 1, 'SET
SCROLL' , 'true|false' ) ;

In the sample dialog, here is the code used in the When-New-Form-Instance trigger:

  -- switch the log to true --
  Set_Custom_Property( 'BLZ.BEAN', 1, 'SETLOG', 'true' ) ;
  -- set the baen image bckground color --
  Set_Custom_Property( 'BLZ.BEAN', 1, 'SETBG', '255,255,255' ) ;
  -- set the JDBC connection information --
  Set_Custom_Property( 'BLZ.BEAN', 1, 'SETCONN', 'jdbc:oracle:thin:@my-machine:1521:XE' ) ;
  Set_Custom_Property( 'BLZ.BEAN', 1, 'SETUSER', 'tutoforms' ) ;
  Set_Custom_Property( 'BLZ.BEAN', 1, 'SETPWD',  'tuto' ) ;
  -- set the image table and column name --
  -- allow the bean to display scrollbars --
  Set_Custom_Property( 'BLZ.BEAN', 1, 'SETSCROLL',  'true' ) ; 

Here is the description of the database table used:

      "NOM" VARCHAR2(50 BYTE),
      "PHOTO" BLOB,

The properties you can get from the JavaBean

Get the image size

Varchar2 :=
Get_Custom_Property( 'BL.BEAN', 1, 'GETSIZE' ) ;

The format returned (width,height) is like the following : 50,120

Accessing to a remote database

Because the JavaBean is executed within an applet, it is not possible to connect to a remote database without a little adaptation:

   - first, the jar file must be signed.
   - second : you have to update the java.policy file stored in the Jinitiator directory

For example, to access to the database located on the machine-name server on the port 1524, add the following lines to the java.policy file:

C:/Program Files/Oracle/JInitiator 1.3.1.xx/lib/security/java.policy file


 permission "machine-name:1524-", "accept,connect,listen,resolve"; 

The sample dialog

     . Download the file
     . Unzip the file
     . run the create_table.sql under the Oracle user you want to test (It creates the sample image table).
     . copy the handleimages.jar file in the <ORACLE_HOME>/forms/java directory
     . Edit your /forms/server/formsweb.cfg file to add both handleimages.jar and classes12.jar (the classes12.jar is located in the <DEV_HOME>/jdbc/lib directory. add a copy of this file in the <DEV_HOME>/forms/java directory).
     . Open the HANDLEIMAGE.fmb module (Oracle Forms 10.1.2)
     . Compile all and run the module

     . Enter a valid file name in the Image File name item then press the Read image file button

Note : If you rebuild the jar file, it has to be signed. (the handleimages.jar file provided in this article is already signed).

Partager cet article

Published by Oracle Forms community - dans Bean - general
commenter cet article


Michael Friedman 06/10/2006

Any solution that requires manually editing files on the client doesn't seem very practical.
Do you have any thoughts on how to manage deployment?

Michael Friedman 16/10/2006

I googled Distrib but could not find it.
Can you give a pointer?
Also, is it suitable for a web based deployment to anonymous users?

Juan Perez 03/01/2007

Hi, I've been tried your pjc, and I've 2 questions:
1.- Why the only image file types i can read from file are JPEG files and not TIFF or BMP types?
2.- When I try to read a blob column from the database, the ii.getIconWidth() and ii.getIconHeight() methods returns -1 (both methods) ? In fact I cant read/write any image file types from / to database, what could be wrong?
Thanks so much for this site, It's very useful

piotr 19/03/2007

I read image from local mashine in item bean but I would like to off border.
help me please

Jacob 02/04/2007

Hi FrancoisI've studied your code for this PJC, because I need to create something similar myself. There is one aspect, that makes your approach unusable to me though, and that's the fact, that your PJC requires the client to actually be able to access the database directly. In a web deployment, where the only access to the database is through the Application Server, it's impossible to do it like this. What I'm wondering is - wouldn't it be a better idea to use WebUtil to physically transfer the file to the application server, and as soon as the transfer has completed, invoke a server-side class made with the Java Importer to store the image in a specific BLOB? Have you ever tried doing it this way?Thanks,Jacob