Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.misc -> Re: Java program in Oracle

Re: Java program in Oracle

From: Harald Maier <maierh_at_myself.com>
Date: Sat, 30 Aug 2003 10:46:13 +0200
Message-ID: <m3fzjjednu.fsf@ate.maierh>


"M" <someone_at_microsoft.com> writes:

> Any example to "write" java code in PL/SQL? I have experience in
> writing PL/SQL but with just little experience in Java.  Any example
> will be helpful.

The following three files work for me. You need to compile the Hello.java file and then load it with the loadjava command.

$ javac Hello.java
$ loadjava -user scott/tiger Hello.class

Hello.sql publishes the java class as PL/SQL function. And HelloTest.sql invokes the function.

Harald

,----[ Hello.java ]
| /* Note: this class is not executable because the class specification
| * does not have a main function.
| */
|
| public class Hello{
| public static String world (){
| return "Hello world";
| }
| }

`----

,----[ Hello.sql ]
| connect scott/tiger;
| create or replace function HELLOWORLD return VARCHAR2 as
| language java name 'Hello.world () return java.lang.String';
| /

`----

,----[ HelloTest.sql ]
| connect scott/tiger;
| variable res varchar2(20);
| call helloworld() into :res;
| print res;

`---- Received on Sat Aug 30 2003 - 03:46:13 CDT

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US