sql 调用java程序,从PL / SQL调用Java

Can any one please help me on this: I want to call one java program from the Pl/SQL, Oracle RDBMS, the below are the settings

Windows 7 machine, Java is installed on

C:\Program Files\Java\jdk1.7.0_02

I created one directory to keep the java files. D:\Java, it has one hello.java file in it.

public class Hello

{

public static String world()

{

return "Hello world";

}

}

this was compiled fine, and the .class file was generated in the same directory.

Since I have to call this function using PL/SQL, here is the PL/SQL function I've written:

create or replace

FUNCTION helloworld RETURN VARCHAR2 AS

LANGUAGE JAVA NAME 'Hello.world () return java.lang.String';

and this is the PL/SQL procedure:

create or replace

PROCEDURE hellow

AS

my_string varchar2(400 char);

begin

my_string:=helloworld();

dbms_output.put_line('The value of the string is ' || my_string);

end;

both the function and the procedure compiled fine using the SQL/developer.

When I tried running this procedure:

set serveroutput on;

execute hellow;

the following error is coming:

Error starting at line 2 in command: execute hellow Error report: ORA-29540: class Hello does not exist ORA-06512: at "ORACLE_SOURCE.HELLOWORLD", line 1 ORA-06512: at "ORACLE_SOURCE.HELLOW", line 5 ORA-06512: at line 1

29540. 00000 - "class %s does not exist"

*Cause: Java method execution failed to find a class with the indicated name.

*Action: Correct the name or add the missing Java class.

I placed the .class file in the bin folder also, but still the same error is coming.

Can anyone please have a look at this.

解决方案

You can also compile and save your java source directly in the database, like stored procedures:

CREATE OR REPLACE AND COMPILE JAVA SOURCE NAMED "Hello" AS

public class Hello

{

public static String world()

{

return "Hello world";

}

};

/

> Java created

Calling this function is straightforward and doesn't need additional settings:

CREATE OR REPLACE

FUNCTION helloworld RETURN VARCHAR2 AS

LANGUAGE JAVA NAME 'Hello.world () return java.lang.String';

/

DECLARE

my_string VARCHAR2(400 CHAR);

BEGIN

my_string := helloworld();

dbms_output.put_line('The value of the string is ' || my_string);

END;

/

> The value of the string is Hello world

> PL/SQL procedure successfully completed

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值