开发者

Assertion failure Aurora (ORA-29516) in Oracle 10g on loadjava

public class HelloWorld{  

  public static void add(int a, int b){  
  System.out.println(a+b);  

  }  
}

and I load it i开发者_如何学编程nto oracle via

loadjava -user system/admin Helloworld.class

This words fine.

After that I write this procedure:

create or replace  
PROCEDURE start_helloworld(a in number, b in number)  
AS language java  
name 'HelloWorld.add(int,int)';  

I want to be able to call the procedure in PL/SQL:

exec start_helloworld(1,1);  

but it gives the error I mentioned.


You can't do console output from Oracle java code, since it's running within the database. Perhaps if you passed in and in/out variable, assigned the output of your arithmetic assignment to the variable and output that in the calling PL/SQL block:

var mynum NUMBER

exec start_helloworld(1,1,:mynum);

print mynum;

You would of course need to modify your java and PL/SQL wrapper to add the new parameter:

public static void add(int a, int b, int c){  
c = a+b;  
}

and

create or replace  
PROCEDURE start_helloworld(a in number, b in number, c in out number)  
AS language java  
name 'HelloWorld.add(int,int,int)';  


I am not an Oracle expert by any means but I have hit this issue recently so I just wanted to comment. For some reason I can't just leave a comment, So here's my answer.

Comment: When I get the Ora-29516 error, it comes with a reason description. Is there more to the error when you get it?

Answer: If your Aurora Assertion error comes with the reason "Uncaught exception System error: java/lang/UnsupportedClassVersionError" =>

I get this error when the version of Java I used to compile the class file isn't the same as the version of Java in Oracle (1.5.0 in 11g). To be sure you match perfectly, let Oracle compile the class for you. You'll get two benefits: 1) You will be sure the Java version matches exactly. 2) You'll have the source code loaded as a database "JAVA SOURCE" object for future reference. For security purposes, you may want to lock it down.

loadjava -user scott/tiger -resolve HelloWorld.java

By using the source file with the resolve option, Oracle will create the source object and compile the code for the class object. If you leave out the -resolve option, Oracle will create the source object and only compile it when it is called. I presume this may have good flexibility options but performance drawbacks.


This error occurs because incompatibility of different java versions in oracle and java compiler. -> oracle version: --TO CHECK JAVA VERSION IN ORACLE

SELECT  dbms_java.get_ojvm_property(PROPSTRING=>'java.version') FROM dual;

FOLLOW THIS STEPS :

//java

class simple{  
    public static String world(){  
     return("Hello Java");  
    }  
} 

Insted of loading class Simple load your java directly, STEP1 :

 loadjava -user system/admin simple.java 

STEP2:

then > create one procedure

CREATE OR REPLACE PROCEDURE PROC_DEMO  as
language java
name 'simple.world()';
/

STEP3:

 declare -- Parameter declaration
  RESULT VARCHAR2(2000);
begin
  -- Please customize initialization
  -- Call the procedure/function
  RESULT := FUNC_DEMO;
  -- Print out the results
  dbms_output.put_line( 'RESULT = ' ||  SUBSTR( RESULT, 1, 255));
end;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜