Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
![]() |
![]() |
Home -> Community -> Usenet -> c.d.o.misc -> Re: Java program in Oracle
"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
![]() |
![]() |