oracle 执行java_oracle调用JAVA类的方法

oracle调用JAVA类的方法主要有以下三种:

1. 用loadjava方法装载;

可能是调试方便,据说这种方法比较通用。

c:\test\hello.java

public class hello

{

public static void main(String[]

args)

{

System.out.println("Hello");

hello

h = new hello();

h.insertM(9);

}

public static

void insertM(int pid)

{

System.out.println("This is the

method insertM.");

}

}

C:\test>loadjava -u test/test@mydb -v -resolve

hello.java

SQL> create procedure prc_hehe as language java name

'hello.main(java.lang.String[])

2  /

过程已创建。

SQL> call prc_hehe();

调用完成。

SQL> set serveroutput on size 2000

SQL> call prc_hehe();

调用完成。

SQL> exec dbms_java.set_output(2000);

PL/SQL 过程已成功完成。

SQL> call prc_hehe();

Hello

This is the method insertM.

调用完成。

SQL>show errors;

修改java类,先删除再装载,方法:

dropjava -u test/test@mydb -v -resolve

hello.java

loadjava -u test/test@mydb -v -resolve

hello.java

2. 用sql语句创建

create or replace and compile java source named hehe

AS

public class

hello

{

public static void msg(String

name)

{

System.out.println("hello,"+name);

}

};

create or replace procedure

prc_hehe

(

p_name

VARCHAR2

)

as

language java name 'hello.msg(java.lang.String)';

/

-- 调用结果

SQL> call prc_hehe('oopp');

hello,oopp

3. 用外部class文件来装载创建

create or replace directory CLASS_DIR  as 'c:\test';

create or replace java class using bfile(class_dir,'hello.class');

create or replace procedure

prc_hello

(

p_name

VARCHAR2

)

as

language java name 'hello.msg(java.lang.String)';

-- 测试结果

SQL> call prc_hello('java');

java

4. 可能出现的错误

SQL> call prc_hello('Jerry');

call

prc_hello('Jerry')

*

第 1 行出现错误:

ORA-29516:

Aurora 断言失败: Assertion failure at eox.c:359

Uncaught exception System

error:   java/lang/UnsupportedClassVersionError

原因:机器装了多个java版本,oracle的java版本低于环境变量设置的版本。

解决方法:用$ORACLE_HOME/jdk/javac 重新编译java文件

-- The End --

  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值