2

I am use oracle 10g and jdk 1.6

I want to call java class from oracle Trigger for that I am tries below-

My java class is-

public class DBTrigger 
{
    public static void logSal()
    {
     System.out.println("In java class");
    }
}

and my oracle trigger is-

CREATE OR REPLACE TRIGGER sal_trig
AFTER UPDATE OF sal ON emp
FOR EACH ROW
WHEN (new.sal > 1.2 * old.sal)
CALL logSal();

but I am able to call it.

so please give me a suggestion.

3
  • Possibly, you can get your answers here Commented Jan 17, 2014 at 4:24
  • But what location of java class. Commented Jan 17, 2014 at 4:31
  • Small comment. When usign Oracle 10g then if fact you're using Java 1.5 (on the DB serverver). Regardless of what JVM version you use your desktop. Commented Jan 17, 2014 at 10:09

2 Answers 2

1

What the link say is

1) create the Java class

CREATE OR REPLACE AND COMPILE JAVA SOURCE NAMED My_JavaClass AS
import java.io.*;
public class DBTrigger 
{
    public static void logSal()
    {
     System.out.println("In java class");
    }
}
/

2) Create a stored procedure (a place holder basically) to call your java class

CREATE OR REPLACE PROCEDURE My_Javaclass_proc
AS LANGUAGE JAVA NAME 'DBTrigger.logSal()';
/

3) Create the trigger and call this procedure

CREATE OR REPLACE TRIGGER sal_trig
AFTER UPDATE OF sal ON emp
FOR EACH ROW
WHEN (new.sal > 1.2 * old.sal)
begin
  My_Javaclass_proc;
end;
/

Try to do using above steps and share the results.

Sign up to request clarification or add additional context in comments.

2 Comments

Again I would say, follow the link, there the example is using parameters :)
I have already gone through this document but due to oracle XE i cant create a java class on sql develoeper. @San can you guide if i have java class in local system then how can i call that class method
0

As mentioned in the oracle docs Calling Java from Database Triggers ,You have to publish your Java method as procedure and have to call that procedure in the trigger.

Have a look at the example in the above link or other example here

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.