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";