2

I've a function in Java that uses an external library (jackson) to work with JSON structures. How can I include my function and all its dependencies in Oracle(12c) PL\SQL? The DB host is an unix os.

8
  • 3
    Review the Oracle Database Java Developers Guide, in particular the section on the loadjava tool. Best of luck. Commented May 4, 2017 at 12:27
  • Java Stored Procedures in one option where a Java method can be used as a database object. What exactly are you trying to achieve? Commented May 4, 2017 at 12:31
  • @user75ponic I needed to work out with JSON structures in a way that PL\SQL native functions were not enough. So I've read and saw that we can add java functions as PL\SQL methods in Oracle, the examples I've seen are the basic ones, where you do not depend on other libs. My function uses an external lib, and I need to know how to add my function and it work properly in Oracle. Commented May 4, 2017 at 12:39
  • 1
    @BrunoRodrigues Use loadjava method from the command prompt to load your Java classes and you must load your dependent JAR files to the database as well to execute the Java method. Commented May 4, 2017 at 12:41
  • 1
    bear in mind you need elevated privileges to load external java classes into the database. You'll need a DBA or similar power user to grant you oracle.aurora.security permissions for the Jackson library. Commented May 4, 2017 at 12:45

1 Answer 1

1

You need to compile your project as fat jar. It means a jar that includes its dependencies on it. Using with zip opener, you can open a fatjar and find jar dependencies in parent fatjar.

After you create your project on unix os which your db runs on go to jar path and run the code below

$ > loadjava -user userName/password@dbName FirstFatJar.jar 

Now you uploaded your jar to oracle. And assume that you have a java class in jar that name is Master and it has a function that name is Atesle which returns java.lang.String. Than connect your oracle db and create java stored procedure/function like that

CREATE or replace FUNCTION atesle1 RETURN VARCHAR2  AS LANGUAGE JAVA NAME 'Master.atesle() return java.lang.String';

Now you can run your java code via oracle store procedure with code below;

select atesle1() from dual
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.