Loading

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

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

Sridevi Koduru said...
July 7, 2016 at 1:00 AM

Regards
Sridevi Koduru (Senior Oracle Apps Trainer Oracleappstechnical.com)
LinkedIn profile - https://in.linkedin.com/in/sridevi-koduru-9b876a8b


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.