java 版 oracle helper,Java教程教案之java中关于OracleHelper包的实例(一)

本文通过实例展示了如何使用Java连接Oracle数据库并执行SQL语句,获取并打印数据。同时,还介绍了如何调用Oracle存储过程,包括存储过程的定义和测试程序的编写。涉及的技术点包括OracleHelper类、数据集操作以及输入输出参数的处理。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

xin3721网络学院为广大学员,准备了丰富了教学视频。相关视频教程地址为:java教程

现在我们就通过实例来演示一下,如何应用这个工具包。代码如下:

jdk1.5.0_12,eclipse-jee-europa-win32,oracle8.1.7

实例所使用的数据库表结构定义:

create table FRIEND

(

SERIALNO    NUMBER(10) not null,

FRIEND_NAME VARCHAR2(50) not null,

FRIEND_AGE  NUMBER(10) not null

)

执行文本性sql语句

import ey.db.type.*;

import ey.db.oracle.*;

public class MyClient …{

public static void main(String[] args)

…{

try

…{

//数据库连接参数

String connectionStr = "jdbc:oracle:thin:@192.168.1.192:1521:itdevdb;htecp;000000";

//文本型sql语句

String commandText = "select * from friend";

//通过OracleHelper的函数执行sql语句

DataSet ds = OracleHelper.ExecuteDataSet(connectionStr, CommandType.Text, commandText);

//从结果集中获取结果数据

for(int i=0;i…{

int serialno = Integer.parseInt( ds.Tables[0].Rows[i].Columns[0].colValue.toString() );

String name  =                   ds.Tables[0].Rows[i].Columns[1].colValue.toString();

int age      = Integer.parseInt( ds.Tables[0].Rows[i].Columns[2].colValue.toString() );

System.out.println("编号:"+serialno+"    姓名:"+name+"    年龄:"+age);

}

}

catch(Exception ex)

…{

ex.printStackTrace();

}

}

}

运行结果:

编号:1 姓名:FuWaer1 年龄:10

编号:2 姓名:FuWaer2 年龄:20

编号:3 姓名:FuWaer3 年龄:30

编号:4 姓名:FuWaer4 年龄:40

执行存储过程

所调用的存储过程定义如下:

procedure SplitFriendByAge(

p_split_age number,

p_down_friends out p_cursor,

p_uper_friends out p_cursor

)is

begin

open p_down_friends for

select * from friend where friend_age 

open p_uper_friends for

select * from friend where friend_age > p_split_age;

end;

其中,一个输入参数p_split_age,两个输出参数分别是p_down_friends、p_uper_friends,两个输出参数的类型p_cursor定义为:type p_cursor is ref cursor;

测试程序如下:

import ey.db.type.*;

import ey.db.oracle.*;

public class MyClient …{

public static void main(String[] args)

…{

try

…{

//数据库连接参数

String connectionStr = "jdbc:oracle:thin:@192.168.1.192:1521:itdevdb;htecp;000000";

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值