Skip to Main Content

Java and JavaScript in the Database

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Calling non-static java methods - simple example?

Roger Ford-OracleFeb 12 2010 — edited Oct 16 2010
I have a java class with non-static methods that I want to call from PL/SQL. I'm having a hard time figuring out how to do this.

Here's an example, as basic as I can think of, where I'm trying to do the same:
create or replace java source named MyNumber as
public class MyNumber
{
  private int value;

  public int getValue() {
     return value;
  }
  public void setValue(int val) {
     value = val;
  }
}
/

alter java class "MyNumber" compile;

create or replace type mynum as object (
  foo varchar2(2000),
  member procedure setvalue( val number ) as language java
  name 'MyNumber.setValue(int)',
  member function getvalue return number as language java
  name 'MyNumber.getValue() return int'
);
/

declare
  foobar mynum;
begin
  foobar := mynum(1);  -- constructor. '1' has no useful meaning
  foobar.setvalue(99); -- call a non-static method
end;
/
This gives me:
ERROR at line 1:
ORA-00932: inconsistent datatypes: expected an IN argument at position 1 that
is an instance of an Oracle type convertible to an instance of a user defined
Java class got an Oracle type that could not be converted to a java class
If I remove the setvalue call it works OK (but isn't very useful)

Can anyone tell me what I need to do to fix this?

The "foo" attribute is unused, but I can't create an oracle object with methods but no attributes.

Edit: accidently added some extra code at the top - now removed.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Nov 13 2010
Added on Feb 12 2010
2 comments
2,969 views