How can I call a Java object/function from Oracle Forms 6i?

, , No Comments
Question :
I am working on a legacy project that is using Oracle Forms 6i (yes, I know its old) to call C++ functions from a PLL library.
Now we need to use Java instead of C++, therefore we need to call Java (Object/Class/Method) from Oracle Forms.
I know its a challenging subject, but I would be really happy if someone could provide a simple example that does the following:
  • Invoking a method from the Java class, passing a int variable (within PL/SQL)
  • Printing the returned value in the Canvas that executed the Function.
A basic example, perhaps a Hello World would be ideal.
I know some PL/SQL, but I am not a Oracle Forms developer; please bear with me.
If this is not possible, could you point me to some other alternatives?


Answer :
4 down vote accepted
Well, after an intensive lookup through the internet I came across a very good resource (in Spanish though): Elias blog about Oracle Forms and Java
I use:
  • Oracle Forms 6i
  • JDK 1.6
With this I managed to create the hello world example:

Configure PATH environment variables:

  • C:\PATH_TO_JAVA\Java\jdk1.6.0\bin;
  • C:\PATH_TO_JAVA\Java\jdk1.6.0\jre\bin;
  • C:\PATH_TO_JAVA\Java\jdk1.6.0\jre\bin\client;
Ex: PATH_TO_JAVA = C:\Program Files

Add to CLASSPATH

  • FORMS_HOME\TOOLS\common60\JAVA\IMPORTER.JAR (In my case FORMS_HOME was C:\orant)
  • PATH_TO_YOUR_JAR\NAME_OF_JAR.jar

Create Java Program

  1. Create with your IDE a simple java program, following is mine:
    public class HolaMundo {
    
      private String hi= "Hey World!!!";
    
      public String GetHi(){
        return this.hola;
      }
    
      public String getMultiply(int a, int b){
        return ""+a*b;
      }
    
      public static void main(String args[]){
    
        HiWorldhm = new HiWorld();
        System.out.println(hm.GetHi());
        System.out.println(hm.getMultiply(5,10));    
    
      }
    }
  2. Export it to Jar file (Path has to be the one you put in CLASSPATH environment variable.

Import the classes to Forms

Create a new project in Oracle Forms and also create a Canvas, in the canvas use a Text and a Button. The name of the button: TEXT_HI_WORLD.
Following click on the Menu: Program > Import Java Classes
If everything went Ok then there will be a new window that will show you the package where the Class is, you extend it until there is the HiWorld class. Import it.
In Program Unit now there will be two files:
  • HIWORLD (Specification)
  • HIWORLD (Body)
This are files generated automatically and needed to use the class.
Then go back to the canvas, right click on the Button and select the Thrigger WHEN-BUTTON-PRESSED, the programming of this will be:
DECLARE
v_wb      ORA_JAVA.JOBJECT;
v_hi      VARCHAR2(20);
BEGIN
v_wb := hiworld.new();
v_hi:= hiworld.getHi(v_wb);
:TEXT_HI_WORLD := v_hi
END;
Now execute the program and click on the button! :)
Hope this helps Java programmers with no much of knowledge on Forms to integrate with legacy systems! :D

0 comments:

Post a Comment