Click to See Complete Forum and Search --> : Call Java From Oracle
Bnt
January 17th, 2006, 06:33 AM
Hi,
Does anyone know how I can call an external java class from an oracle stored procedure. Please note, I do not want to call a Java Stored Procedure, I am looking at running a class sitting in a file system from oracle.
Thanks
Byron
exterminator
January 17th, 2006, 12:38 PM
There is a loadjava command that loads an already compiled java class into the SCOTT schema of the db. Something like this:
> loadjava -user scott/tiger -oci8 -resolve MyJavaClass.class
Verify if this was loaded using "exec myjava.showobjects" command. Now you create a pl/sql wrapper function over the java code. A sample:
CREATE OR REPLACE FUNCTION
myfunction
(/*arguments*/)
RETURN
/*return type*/
AS LANGUAGE JAVA
NAME ' MyClass.myMethod(/*arguments*/ ';
/*myMethod being a static function in MyClass*/
Note that you need to specify fully qualified names for the types (except for fundamental ones) like java.lang.String and not simply 'String'. To reverse the changes of loadjava - you use the utility dropjava. That's all from now. Code is far from tested so you may want to look into the details in a documentation/manual. I am not an expert at this so please don't tell me that it did not work :D.. By the way, you will find this book useful - Oracle PL/SQL programming by Steven Feuerstein (with Bill Pribyl). It deals this stuff well, from quite basic. You may find more stuff on the net searching for the keywords I used above. All the best. Hope this helps. Regards.
Bnt
January 18th, 2006, 02:35 AM
Hi exterminator,
Thanks for the reply, but I'm not looking at creating a Java Stored Proc (I already have a few of those implemented), I wan't to call some classes sitting outside of oracle (on the unix filesystem). But I have a solution now though, I'm going to create a Java Stored Proc, that creates a Runtime process so I can execute shell commands, from the shell I will call my external classes.
Thanks again for your help.
Byron
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.