如何从 Oracle Forms 6i 调用 Java 对象/函数?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5890868/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-30 13:18:43  来源:igfitidea点击:

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

javaclassmethodsinvokeoracleforms

提问by will824

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.

我正在处理一个使用 Oracle Forms 6i(是的,我知道它是旧的)从 PLL 库调用 C++ 函数的遗留项目。

Now we need to use Java instead of C++, therefore we need to call Java (Object/Class/Method) from Oracle Forms.

现在我们需要使用 Java 而不是 C++,因此我们需要从 Oracle Forms 中调用 Java(对象/类/方法)。

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.
  • 从 Java 类调用方法,传递一个 int 变量(在 PL/SQL 中)
  • 在执行函数的 Canvas 中打印返回值。

A basic example, perhaps a Hello World would be ideal.

一个基本的例子,也许一个 Hello World 是理想的。

I know some PL/SQL, but I am not a Oracle Forms developer; please bear with me.

我知道一些 PL/SQL,但我不是 Oracle Forms 开发人员;请多多包涵。

If this is not possible, could you point me to some other alternatives?

如果这是不可能的,你能指出我一些其他的选择吗?

回答by will824

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

好吧,在通过互联网进行密集查找后,我发现了一个非常好的资源(尽管是西班牙语):关于 Oracle Forms 和 Java 的 Elias 博客

I use:

我用:

  • Oracle Forms 6i
  • JDK 1.6
  • 甲骨文表格 6i
  • JDK 1.6

With this I managed to create the hello world example:

有了这个,我设法创建了 hello world 示例:



Configure PATH environment variables:

配置PATH环境变量:

  • 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;
  • 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

例如: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
  • FORMS_HOME\TOOLS\common60\JAVA\IMPORTER.JAR(在我的情况下 FORMS_HOME 是 C:\orant)
  • PATH_TO_YOUR_JAR\NAME_OF_JAR.jar


Create Java Program

创建 Java 程序

  1. Create with your IDE a simple java program, following is mine:

    public class HiWorld{        
      private String hi="Hello World!";
    
      public String getHi(){
        return this.hi;
      }
    
      public String getMultiply(int a, int b){
        return ""+a*b;
      }
    
      public static void main(String args[]){            
        HiWorld hm = 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.

  1. 用你的 IDE 创建一个简单的 java 程序,下面是我的:

    public class HiWorld{        
      private String hi="Hello World!";
    
      public String getHi(){
        return this.hi;
      }
    
      public String getMultiply(int a, int b){
        return ""+a*b;
      }
    
      public static void main(String args[]){            
        HiWorld hm = new HiWorld();
        System.out.println(hm.getHi());
        System.out.println(hm.getMultiply(5,10));                
      }
    }
    
  2. 将其导出为 Jar 文件(路径必须是您放入 CLASSPATH 环境变量中的那个。

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.

在 Oracle Forms 中创建一个新项目并创建一个画布,在画布中使用一个文本和一个按钮。按钮名称:TEXT_HI_WORLD。

Following click on the Menu: Program > Import Java Classes

依次单击菜单:程序 > 导入 Java 类

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.

如果一切顺利,那么将会出现一个新窗口,向您显示 Class 所在的包,您可以将其扩展到 HiWorld 类。导入它。

In Program Unit now there will be two files:

现在在程序单元中将有两个文件:

  • HIWORLD (Specification)
  • HIWORLD (Body)
  • HIWORLD(规格)
  • HIWORLD(身体)

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:

然后回到画布,右击Button,选择Thrigger WHEN-BUTTON-PRESSED,这样的编程就是:

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

希望这可以帮助对 Forms 知之甚少的 Java 程序员与遗留系统集成!:D

回答by DearMissDarling

I've done this before, and with a simple class this should work, but when you try to develop something more complicated, I recommend extend from the VBean class, you can find the library within oracle's forms installation folders (frmall.jar).

我以前做过这个,用一个简单的类应该可以工作,但是当您尝试开发更复杂的东西时,我建议从 VBean 类扩展,您可以在 oracle 的表单安装文件夹 (frmall.jar) 中找到该库。

回答by user2700685

// el programa corregido.

public class HolaMundo {

private String hi= "Hey World!!!";

  public String GetHi(){
    return this.hi;
  }

public static void main(String args[]){

    HolaMundo  hm = new HolaMundo();
    System.out.println(hm.GetHi());

  }
}