如何从Oracle PL / SQL调用Java jar文件?

时间:2013-01-31 02:00:30

标签: java oracle11g onejar

我的客户希望能够从Oracle PL / SQL调用jar文件。

Java 1.6,Oracle 11g R2

我该怎么做?

2 个答案:

答案 0 :(得分:2)

我对loadjava(将类加载到Oracle中的程序)进行了一些研究。 听起来像是屁股上的疼痛。

所以我选择在Oracle之外运行我的jar,但是通过PL / SQL从Oracle DBMS_SCHEDULER调用。

以下是:

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;  
/

答案 1 :(得分:0)

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.