This discussion is archived
1 2 Previous Next 16 Replies Latest reply: Jul 22, 2013 11:38 PM by Sachinmrt RSS

How to use java programe in oracle form

Sachinmrt Explorer
Currently Being Moderated

Hello Expert,

 

My Config is : -

 

Forms [32 Bit] Version 11.1.1.3.0 (Production)

Jdeveloper - 10.1.3

 

I want to use the java programe in form builder. I create the one java class in Jdeveloper -

 

package demo;

import java.net.InetAddress;

import java.net.NetworkInterface;

import java.net.SocketException;

import java.net.UnknownHostException;

 

public class get_info{

   public static void main(String[] args){

 

   ch_add();

 

   }

   public static void ch_add()

   {

  InetAddress ip;

  try { 

  ip = InetAddress.getLocalHost();

  /*System.out.println("Current IP address : " + ip.getHostAddress());  */

  NetworkInterface network = NetworkInterface.getByInetAddress(ip);

  byte[] mac = network.getHardwareAddress();

  /*System.out.print("Current MAC address : ");   */

  StringBuilder sb = new StringBuilder();            

  for (int i = 0; i < mac.length; i++)

                {

  sb.append(String.format("%02X%s", mac[i], (i < mac.length - 1) ? "-" : ""));

  }

  System.out.println(sb.toString()); 

  } catch (UnknownHostException e) {

  e.printStackTrace();

  } catch (SocketException e){

  e.printStackTrace();

 

  }

 

   }

 

}

 

 

and this into Formweb.cfg and default.env and also add into Form_class_path. After that i import this java into forms.

 

 

Code genertated -

 

PACKAGE BODY get_info IS

 

 

  --

  -- DO NOT EDIT THIS FILE - it is machine generated!

  --

 

 

  args   JNI.ARGLIST;

 

 

  -- Constructor for signature ()V

  FUNCTION new RETURN ORA_JAVA.JOBJECT IS

  BEGIN

    args := NULL;

    RETURN (JNI.NEW_OBJECT('demo/get_info', '()V', args));

  END;

 

 

  -- Method: main ([Ljava/lang/String;)V

  PROCEDURE main(

    a0    ORA_JAVA.JARRAY) IS

  BEGIN

    args := JNI.CREATE_ARG_LIST(1);

    JNI.ADD_OBJECT_ARG(args, a0, '[Ljava/lang/String;');

    JNI.CALL_VOID_METHOD(TRUE, NULL, 'demo/get_info', 'main', '([Ljava/lang/String;)V', args);

  END;

 

 

  -- Method: ch_add ()V

  PROCEDURE ch_add IS

  BEGIN

    args := NULL;

    JNI.CALL_VOID_METHOD(TRUE, NULL, 'demo/get_info', 'ch_add', '()V', args);

  END;

 

 

  -- Method: wait (J)V

  PROCEDURE wait(

    obj   ORA_JAVA.JOBJECT,

    a0    NUMBER) IS

  BEGIN

    args := JNI.CREATE_ARG_LIST(1);

    JNI.ADD_LONG_ARG(args, a0);

    JNI.CALL_VOID_METHOD(FALSE, obj, 'demo/get_info', 'wait', '(J)V', args);

  END;

 

 

  -- Method: wait ()V

  PROCEDURE wait(

    obj   ORA_JAVA.JOBJECT) IS

  BEGIN

    args := NULL;

    JNI.CALL_VOID_METHOD(FALSE, obj, 'demo/get_info', 'wait', '()V', args);

  END;

 

 

  -- Method: wait (JI)V

  PROCEDURE wait(

    obj   ORA_JAVA.JOBJECT,

    a0    NUMBER,

    a1    NUMBER) IS

  BEGIN

    args := JNI.CREATE_ARG_LIST(2);

    JNI.ADD_LONG_ARG(args, a0);

    JNI.ADD_INT_ARG(args, a1);

    JNI.CALL_VOID_METHOD(FALSE, obj, 'demo/get_info', 'wait', '(JI)V', args);

  END;

 

 

  -- Method: equals (Ljava/lang/Object;)Z

  FUNCTION equals(

    obj   ORA_JAVA.JOBJECT,

    a0    ORA_JAVA.JOBJECT) RETURN BOOLEAN IS

  BEGIN

    args := JNI.CREATE_ARG_LIST(1);

    JNI.ADD_OBJECT_ARG(args, a0, 'java/lang/Object');

    RETURN JNI.CALL_BOOLEAN_METHOD(FALSE, obj, 'demo/get_info', 'equals', '(Ljava/lang/Object;)Z', args);

  END;

 

 

  -- Method: toString ()Ljava/lang/String;

  FUNCTION toString(

    obj   ORA_JAVA.JOBJECT) RETURN VARCHAR2 IS

  BEGIN

    args := NULL;

    RETURN JNI.CALL_STRING_METHOD(FALSE, obj, 'demo/get_info', 'toString', '()Ljava/lang/String;', args);

  END;

 

 

  -- Method: hashCode ()I

  FUNCTION hashCode(

    obj   ORA_JAVA.JOBJECT) RETURN NUMBER IS

  BEGIN

    args := NULL;

    RETURN JNI.CALL_INT_METHOD(FALSE, obj, 'demo/get_info', 'hashCode', '()I', args);

  END;

 

 

  -- Method: getClass ()Ljava/lang/Class;

  FUNCTION getClass(

    obj   ORA_JAVA.JOBJECT) RETURN ORA_JAVA.JOBJECT IS

  BEGIN

    args := NULL;

    RETURN JNI.CALL_OBJECT_METHOD(FALSE, obj, 'demo/get_info', 'getClass', '()Ljava/lang/Class;', args);

  END;

 

 

  -- Method: notify ()V

  PROCEDURE notify(

    obj   ORA_JAVA.JOBJECT) IS

  BEGIN

    args := NULL;

    JNI.CALL_VOID_METHOD(FALSE, obj, 'demo/get_info', 'notify', '()V', args);

  END;

 

 

  -- Method: notifyAll ()V

  PROCEDURE notifyAll(

    obj   ORA_JAVA.JOBJECT) IS

  BEGIN

    args := NULL;

    JNI.CALL_VOID_METHOD(FALSE, obj, 'demo/get_info', 'notifyAll', '()V', args);

  END;

 

 

 

 

BEGIN

  NULL;

END;

 

 

Now i want to call the o/p of Java programe in oracle text item. Please help me. It's very urgent. I am not good in Java.

  • 1. Re: How to use java programe in oracle form
    Christian Erlinger Guru
    Currently Being Moderated

    Sounds like your question from here: How to run the oracle form in linux system

     

    Now do you want to use a java bean or the java importer like you did above? Those are different things, and will behave differently. In your case you'll get the MAC address of the application server if you get it to work. If you want the MAC address of the client then you need a java bean.

    See http://fdtool.free.fr/forms-pjc-bean/first-bean/first_bean.pdf

     

    for the java importer see here:

    http://www.oracle.com/technetwork/developer-tools/forms/javaimporter-130505.pdf

     

    cheers

  • 2. Re: How to use java programe in oracle form
    Sachinmrt Explorer
    Currently Being Moderated

    Sir,

     

    I create the simple jar file and i want to use into the form.

    Can you provide me the code for form builder where i can see the output of jar file.

  • 3. Re: How to use java programe in oracle form
    Christian Erlinger Guru
    Currently Being Moderated

    As said: what kind do you want to use? Java Beans or the Java Importer? Have a look at the 2 documents I gave you as they contain informations on both technologies and how to use them. Basing on your code you don't even have a method returning something which can be used in forms, so I am entirely unsure what you want to do.

     

    cheers

  • 4. Re: How to use java programe in oracle form
    Sachinmrt Explorer
    Currently Being Moderated

    Sir i use java importer.

     

    PACKAGE BODY get_info IS

     

     

      --

      -- DO NOT EDIT THIS FILE - it is machine generated!

      --

     

     

      args   JNI.ARGLIST;

     

     

      -- Constructor for signature ()V

      FUNCTION new RETURN ORA_JAVA.JOBJECT IS

      BEGIN

        args := NULL;

        RETURN (JNI.NEW_OBJECT('demo/get_info', '()V', args));

      END;

     

     

      -- Method: main ([Ljava/lang/String;)V

      PROCEDURE main(

        a0    ORA_JAVA.JARRAY) IS

      BEGIN

        args := JNI.CREATE_ARG_LIST(1);

        JNI.ADD_OBJECT_ARG(args, a0, '[Ljava/lang/String;');

        JNI.CALL_VOID_METHOD(TRUE, NULL, 'demo/get_info', 'main', '([Ljava/lang/String;)V', args);

      END;

     

     

      -- Method: ch_add ()V

      PROCEDURE ch_add IS

      BEGIN

        args := NULL;

        JNI.CALL_VOID_METHOD(TRUE, NULL, 'demo/get_info', 'ch_add', '()V', args);

      END;

     

     

      -- Method: wait (J)V

      PROCEDURE wait(

        obj   ORA_JAVA.JOBJECT,

        a0    NUMBER) IS

      BEGIN

        args := JNI.CREATE_ARG_LIST(1);

        JNI.ADD_LONG_ARG(args, a0);

        JNI.CALL_VOID_METHOD(FALSE, obj, 'demo/get_info', 'wait', '(J)V', args);

      END;

     

     

      -- Method: wait ()V

      PROCEDURE wait(

        obj   ORA_JAVA.JOBJECT) IS

      BEGIN

        args := NULL;

        JNI.CALL_VOID_METHOD(FALSE, obj, 'demo/get_info', 'wait', '()V', args);

      END;

     

     

      -- Method: wait (JI)V

      PROCEDURE wait(

        obj   ORA_JAVA.JOBJECT,

        a0    NUMBER,

        a1    NUMBER) IS

      BEGIN

        args := JNI.CREATE_ARG_LIST(2);

        JNI.ADD_LONG_ARG(args, a0);

        JNI.ADD_INT_ARG(args, a1);

        JNI.CALL_VOID_METHOD(FALSE, obj, 'demo/get_info', 'wait', '(JI)V', args);

      END;

     

     

      -- Method: equals (Ljava/lang/Object;)Z

      FUNCTION equals(

        obj   ORA_JAVA.JOBJECT,

        a0    ORA_JAVA.JOBJECT) RETURN BOOLEAN IS

      BEGIN

        args := JNI.CREATE_ARG_LIST(1);

        JNI.ADD_OBJECT_ARG(args, a0, 'java/lang/Object');

        RETURN JNI.CALL_BOOLEAN_METHOD(FALSE, obj, 'demo/get_info', 'equals', '(Ljava/lang/Object;)Z', args);

      END;

     

     

      -- Method: toString ()Ljava/lang/String;

      FUNCTION toString(

        obj   ORA_JAVA.JOBJECT) RETURN VARCHAR2 IS

      BEGIN

        args := NULL;

        RETURN JNI.CALL_STRING_METHOD(FALSE, obj, 'demo/get_info', 'toString', '()Ljava/lang/String;', args);

      END;

     

     

      -- Method: hashCode ()I

      FUNCTION hashCode(

        obj   ORA_JAVA.JOBJECT) RETURN NUMBER IS

      BEGIN

        args := NULL;

        RETURN JNI.CALL_INT_METHOD(FALSE, obj, 'demo/get_info', 'hashCode', '()I', args);

      END;

     

     

      -- Method: getClass ()Ljava/lang/Class;

      FUNCTION getClass(

        obj   ORA_JAVA.JOBJECT) RETURN ORA_JAVA.JOBJECT IS

      BEGIN

        args := NULL;

        RETURN JNI.CALL_OBJECT_METHOD(FALSE, obj, 'demo/get_info', 'getClass', '()Ljava/lang/Class;', args);

      END;

     

     

      -- Method: notify ()V

      PROCEDURE notify(

        obj   ORA_JAVA.JOBJECT) IS

      BEGIN

        args := NULL;

        JNI.CALL_VOID_METHOD(FALSE, obj, 'demo/get_info', 'notify', '()V', args);

      END;

     

     

      -- Method: notifyAll ()V

      PROCEDURE notifyAll(

        obj   ORA_JAVA.JOBJECT) IS

      BEGIN

        args := NULL;

        JNI.CALL_VOID_METHOD(FALSE, obj, 'demo/get_info', 'notifyAll', '()V', args);

      END;

     

     

     

     

    BEGIN

      NULL;

    END;

     

    I read both document which is given by you.

     

    Basicaly i don't know how to call java program in form builder.

     

    I wrote this code on When-button-pressed

     

    DECLARE

    jo ora_java.jobject;

    rv varchar2(1500);

    ex ora_java.jobject;

    BEGIN

    jo := get_info.new;

     

     

    rv:=get_info.ch_add(jo );

     

     

    EXCEPTION

    WHEN ORA_JAVA.JAVA_ERROR then

      message (' Unable to call out to Java, ' ||ORA_JAVA.LAST_ERROR );

      message('');

    WHEN ORA_JAVA.EXCEPTION_THROWN then

      ex := ORA_JAVA.LAST_EXCEPTION;

      message(' Unable to call out to Java ' ||Exception_.toString (ex ) );

      message(' Unable to call out to Java ' ||Exception_.toString (ex ) );

    END;

     

     

    No error comes and no output comes. I want the client MAC ID. please guide me where i need to change the code.

  • 5. Re: How to use java programe in oracle form
    Christian Erlinger Guru
    Currently Being Moderated

    You don't get the client MAC ID with the Java Importer. The Java Importer will execute your Java Class on the Application Server, and thus you'll get the MAC of the Application Server.

     

    Just for starters, you might use something like this:

     

    package com.industrieinformatik.test;
    import java.net.InetAddress;
    import java.net.NetworkInterface;
    import java.net.SocketException;
    import java.net.UnknownHostException;
    public class ClientInfo {
      public String getMacAddress() throws UnknownHostException, SocketException {
        InetAddress ip = InetAddress.getLocalHost();
        NetworkInterface network = NetworkInterface.getByInetAddress(ip);
        byte[] mac = network.getHardwareAddress();
        String ret = new String();
        for (int i = 0; i < mac.length; i++){
          ret += String.format("%02X%s", mac[i], (i < mac.length - 1) ? "-" : "");
        }
        return ret;
      }
    }

     

    Now all you'd need to do is to call getMacAddress() in the getProperty method of your Bean class as shown in the Java Bean tutorial.

     

    cheers

  • 6. Re: How to use java programe in oracle form
    Sachinmrt Explorer
    Currently Being Moderated

    Thanks sir for quick response.

    Please tell me what code i write on Form Builder button pressed??

     

     

    I wrote this code on jdeveloper, now tell me what i write on Implementation Class property of BEAN and what i use in Button click :-

     

    Currently write the demo1.demo1 in BEAN Implementation class and on Button Click i write :-

     

    :t1 := Get_custom_property('BEAN',1,'getMacAddress');

     

     

    This is my Jdeveloper code :-

    package demo1;

     

     

     

     

    import java.net.InetAddress; 

    import java.net.NetworkInterface; 

    import java.net.SocketException; 

    import java.net.UnknownHostException; 

    public class demo1 { 

      public String getMacAddress() throws UnknownHostException, SocketException { 

        InetAddress ip = InetAddress.getLocalHost(); 

        NetworkInterface network = NetworkInterface.getByInetAddress(ip); 

        byte[] mac = network.getHardwareAddress(); 

        String ret = new String(); 

        for (int i = 0; i < mac.length; i++){ 

          ret += String.format("%02X%s", mac[i], (i < mac.length - 1) ? "-" : ""); 

        } 

        return ret; 

      } 

     

    But no output comes. Please tell me where i am doing wrong. Sir please give me some helpful document regarding java bean and form.

  • 7. Re: How to use java programe in oracle form
    Christian Erlinger Guru
    Currently Being Moderated

    This is all explained in http://fdtool.free.fr/forms-pjc-bean/first-bean/first_bean.pdf

     

    In essence you'd need:

    - a Java Class extending oracle.forms.ui.VBean where you'd implement the getProperty method as shown in the article

    - a unique property name of your choosing

    - a Forms Item of type Bean Area which needs to be visible and on a Canvas

    - you'd then could call your method using get_custom_property(<item>, 1, <property_name>)

     

    Just adapt the sample from the above tutorial. You could of course also use the FBean package so you won't need to extend VBean but simply from any Class extending Container. As a start maybe you should redo the whole tutorial to get a grip on the how's and why's.

     

    cheers

  • 8. Re: How to use java programe in oracle form
    Sachinmrt Explorer
    Currently Being Moderated

    Thanks sir for your support. At last i have done it. Really thanks for your valuable support.

    But now i have face another problem some system show me digital signature message and after that form stuck.

     

    message is -

     

    The application's digital signature cannot be verified.

     

    This Jar file run on 1.6.0.18 and 1.6.0.20 jre but not run on 1.6.0.34. Please suggest me what to do now??

    My jar file already signed by jarsigner.

  • 9. Re: How to use java programe in oracle form
    Christian Erlinger Guru
    Currently Being Moderated

    Ah, that's a nasty problem in the JPI. Not sure when it's fixed, but you should try a more recent version like 1.6u45 (or 1.6u51 if you have access to MOS). Another option might be to bring your Forms installation to the latest Patchlevel (11.1.1.7) and use a recent version of Java7 instead.

     

    cheers

  • 10. Re: How to use java programe in oracle form
    Sachinmrt Explorer
    Currently Being Moderated

    Some system show me this error.

     

     

    Java Plug-in 10.25.2.17

    Using JRE version 1.7.0_25-b17 Java HotSpot(TM) Client VM

    User home directory = C:\Users\Administrator

     

    java.lang.ClassNotFoundException: demo3.demo3

      at sun.plugin2.applet.Applet2ClassLoader.findClass(Unknown Source)

      at sun.plugin2.applet.Plugin2ClassLoader.loadClass0(Unknown Source)

      at sun.plugin2.applet.Plugin2ClassLoader.loadClass(Unknown Source)

      at sun.plugin2.applet.Plugin2ClassLoader.loadClass(Unknown Source)

      at java.lang.ClassLoader.loadClass(Unknown Source)

      at java.lang.Class.forName0(Native Method)

      at java.lang.Class.forName(Unknown Source)

      at oracle.forms.handler.UICommon.instantiate(Unknown Source)

      at oracle.forms.handler.UICommon.onCreate(Unknown Source)

      at oracle.forms.handler.JavaContainer.onCreate(Unknown Source)

      at oracle.forms.engine.Runform.onCreateHandler(Unknown Source)

      at oracle.forms.engine.Runform.processMessage(Unknown Source)

      at oracle.forms.engine.Runform.processSet(Unknown Source)

      at oracle.forms.engine.Runform.onMessageReal(Unknown Source)

      at oracle.forms.engine.Runform.onMessage(Unknown Source)

      at oracle.forms.engine.Runform.sendInitialMessage(Unknown Source)

      at oracle.forms.engine.Runform.startRunform(Unknown Source)

      at oracle.forms.engine.Main.createRunform(Unknown Source)

      at oracle.forms.engine.Main.start(Unknown Source)

      at com.sun.deploy.uitoolkit.impl.awt.AWTAppletAdapter.start(Unknown Source)

      at sun.plugin2.applet.Plugin2Manager$AppletExecutionRunnable.run(Unknown Source)

      at java.lang.Thread.run(Unknown Source)

     

     

    I think some thing should me change into formweb.cfg for for new jre version, Like class id and mime type.

    Please suggest??

  • 11. Re: How to use java programe in oracle form
    Christian Erlinger Guru
    Currently Being Moderated

    Please post the archive and the jpi_mimetype entries of your webconfig. Also did you patch your system to 11.1.1.7? I am not entirely sure but I think 11.1.1.3 isn't certified with Java7.

     

    cheers

  • 12. Re: How to use java programe in oracle form
    Sachinmrt Explorer
    Currently Being Moderated

    Please check and suggest :-

     

    baseHTMLJInitiator=webutiljpi.htm

    jpi_classid=clsid:CAFEEFAC-0016-0000-0012-ABCDEFFEDCBA

    jpi_codebase=/jre-1_6_0_26-windows-i586.exe#Version=1,6,0,26

    jpi_mimetype=application/x-java-applet

    jpi_download_page=/jre-1_6_0_26-windows-i586.exe

  • 13. Re: How to use java programe in oracle form
    Christian Erlinger Guru
    Currently Being Moderated

    Didn't you say you were on Forms 11.1.1.3? If so this

     

    baseHTMLJInitiator=webutiljpi.htm

     

    can't be correct. There is no baseHTMLJInitiator parameter in Forms 11. Also the archive entry is missing. Did you add your jar file there?

     

    cheers

  • 14. Re: How to use java programe in oracle form
    Sachinmrt Explorer
    Currently Being Moderated

    Sir this is my full configuration.

    I don't know what is baseHTMLJInitiator and why it's use.

    jpi_classid and jpi_codebase and jpi_mimetype what is the use of these value??

    Please suggest??

     

    baseHTMLJInitiator=webutiljpi.htm

    jpi_classid=clsid:CAFEEFAC-0016-0000-0012-ABCDEFFEDCBA

    jpi_codebase=/jre-1_6_0_26-windows-i586.exe#Version=1,6,0,26

    jpi_mimetype=application/x-java-applet

    jpi_download_page=/jre-1_6_0_26-windows-i586.exe

     

     

    WebUtilArchive=frmwebutil.jar,jacob.jar,demo3.jar,

    WebUtilLogging=off

    WebUtilLoggingDetail=normal

    WebUtilErrorMode=Alert

    WebUtilDispatchMonitorInterval=5

    WebUtilTrustInternal=true

    WebUtilMaxTransferSize=16384

    baseHTML=webutilbase.htm

    baseHTMLie=webutilbase.htm

    archive=frmall.jar,jacob.jar,frmwebutil.jar,demo3.jar

     

     

    form=d:\local\demo3.fmx

    envFile=default1.env

    debug=no

    host=

    port=

    buffer=1024

    pageTitle=TEST

    #width=100%

    #height=100%

    separateFrame=True

    lookandfeel=oracle

    splashScreen=No

    background=No

    #colorScheme=blue

    logo=No

    escapeparams=false

1 2 Previous Next

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points