Question

My customer wants to be able to call a jar file from Oracle PL/SQL.

Java 1.6, Oracle 11g R2

How do I do this?

Was it helpful?

Solution

I did a bit of research into loadjava (the program that loads classes into Oracle). Sounded like a pain in the butt.

So I opted to run my jar outside Oracle but called from Oracle DBMS_SCHEDULER by PL/SQL.

Here's how:

BEGIN
DBMS_SCHEDULER.CREATE_PROGRAM (
program_name            => 'testjar',
program_type            => 'EXECUTABLE',
program_action          => 'C:\MYSTUFF\testjar.bat',
enabled                 => TRUE,
comments                => 'test testjar'
);
END;
/

begin  
dbms_scheduler.create_job  
 (job_name => 'testjar_job',  
  program_name=> 'testjar',    
  enabled=>true,  
  auto_drop=>false,  
  comments=>'Only run immediately by dbms_scheduler.run_job');  
end; 
/


begin  
    dbms_scheduler.run_job('testjar_job',TRUE);  
end;  
/

OTHER TIPS

After playing around I found out that the schema JAR_NAME.jar///ClassName.methodName(.... works.

So for example:

Function do()
return String
AS
      LANGUAGE java
         NAME 'my_jar.jar///MyClass.myMethod() return oracle.sql.String';

Note that it seems like some jar name files does not work. For example I had problems with a "-" in jar.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top