Re: Oracle and Java packages

From: Boris Bunjan <boris.bunjan_at_zg.hinet.hr>
Date: Tue, 30 Jan 2001 16:08:26 +0100
Message-ID: <956lg9$19iv$1_at_as121.tel.hr>


"Alan" <campbela_691021_at_my-deja.com> wrote in message news:9542ro$t3u$1_at_nnrp1.deja.com...
> I have been trying to use the Java functionalility of the Oracle 8
> database (8.1.6.0.0) but have been experiencing some problems.
>
> I have a small demo package that will not 'run'
>
> --------------------------------------------------------------------
> create or replace java source named "Postcode" as
> import java.io.*;
> import java.net.*;
> public class Postcode
> {
> static public int enquiry(String ipHost)
> {
> Socket pcSocket = null;
> PrintWriter out = null;
> BufferedReader in = null;
> String ipSendBuffer = null;
> String ipRecvBuffer = null;
> String tpHeader = "PC01000000000000";
> int ipPort = 7;
> pcSocket = new Socket(ipHost, ipPort);
> return 1;
> }
> }
> /
> --------------------------------------------------------------------
>
> When I execute the above command in SQL*Plus, it tells me 'Java
> created'. I then do the following :-
>
> create or replace function postcode_enquiry(ipaddress varchar2) return
> number as
> language java name 'Postcode.enquiry(java.lang.String) return
> java.lang.int';
> /
>
> This tells me that the function has been created. When I try to use
> the function :-
>
> select postcode_enquiry('test') from dual;
>
> I get the following error :-
>
> ERROR at line 1:
> ORA-29541: class CAMPBELA.Postcode could not be resolved
>
> If I edit the Java routine and remove the line :-
>
> pcSocket = new Socket(ipHost, ipPort);
>
> and try again, it works.
> Obviously, its a fairly usless Java routine because it doesnt do
> anything.
>
> I assume that the Java class failes to 'compile' because of the socket
> call, butI dont know why. Any ideas ?
>
> Thanks
>
> Alan
> --
> Alan Campbell
> alanc_at_mullen.demon.co.uk
>
>
> Sent via Deja.com
> http://www.deja.com/

Look for compilation errors with select * from user_errors where type='JAVA SOURCE' You have to catch exceptions, or tell compiler that function can throw them: ...
public class Postcode
{
static public int enquiry(String ipHost) throws UnknownHostException, IOException
...

Boris Received on Tue Jan 30 2001 - 16:08:26 CET

Original text of this message