Tuesday, June 2, 2015

Calling Java Program from Oracle PLSQL with Example (Using Loadjava Utility)













In this post, let us see how to execute a Java program from PLSQL or simply Oracle Database. I tried to explain in Step by Step Approach.
1.      Create a Java Class and place it in the OS location of the server.
2.      Load the Java class file into Oracle Database using loadjava utility
3.      Prepare the wrapper PLSQL function to call the Java Class
4.      Verify the Execution of the Java class from Oracle DB

Step1: Create a Java Class and place it in the OS location of the server.


public class Math{
  public static int Sum (int x, int y){
  return (x + y );
  }
  public static int difference (int x, int y ){
  return (x-y);
  }
}

clip_image002[9]

Step2: Load the Java class file into Oracle Database using loadjava utility


loadjava –user <db_username>/<db_password> <java Source file name>
clip_image004[9]
We can verify the loaded objects from Database,
clip_image005[9]

Step3: Prepare the wrapper PLSQL function to call the Java Class


CREATE OR REPLACE FUNCTION do_sum (x NUMBER, y NUMBER)
-- Return type should match the return type of java member function
RETURN NUMBER
AS
   LANGUAGE JAVA
   NAME 'Math.Sum(int,int) return int';
/
clip_image006[9]

4.Verify the Execution of the Java class from Oracle DB


clip_image007[9]










Happy Sharing Smile

0 Responses to “Calling Java Program from Oracle PLSQL with Example (Using Loadjava Utility)”

Post a Comment

Disclaimer

The ideas, thoughts and concepts expressed here are my own. They, in no way reflect those of my employer or any other organization/client that I am associated. The articles presented doesn't imply to any particular organization or client and are meant only for knowledge Sharing purpose. The articles can't be reproduced or copied without the Owner's knowledge or permission.