二、编写JAVA代码测试过程
/*
* 创建日期: 2003-8-8
*/
package JDBC;
/**
* 作者:may
* 时间:15:09:23
*/
import java.sql.*;
import oracle.jdbc.driver.*;
public class proctest {
public static void main(String[] args) {
proctest pc = new proctest();
pc.ShowContent();
}
String sDBDriver="oracle.jdbc.driver.OracleDriver";
String sConnStr="jdbc:oracle:thin:@10.3.8.48:1521:ORADB";
Connection connect=null;
ResultSet rs = null;
public proctest(){
try{
Class.forName(sDBDriver);
}
catch(ClassNotFoundException e){
System.err.println(e.getMessage());
}
}
public ResultSet ShowContent()
{
try{
connect = DriverManager.getConnection(sConnStr,"SHUIBJ","SHUIBJ");
CallableStatement stmt = connect.prepareCall("{call PKG_TEST.GET(?,?,?)}");
stmt.setString(1,"all"); //输入参数
stmt.registerOutParameter(2,Types.CHAR); //输出参数为普通参数
stmt.registerOutParameter(3,OracleTypes.CURSOR); //输出参数为结果集参数
stmt.executeQuery();
rs = ((OracleCallableStatement) stmt).getCursor(3); //得到输出结果集参数
ResultSetMetaData rsmd = rs.getMetaData();
int numberOfColumns = rsmd.getColumnCount();
String str = stmt.getString(2);
System.out.println("第二个参数为:"+str);
System.out.println("结果集列数"+numberOfColumns);
//列出结果集中的记录
ResultSetMetaData md = rs.getMetaData();
int nColumns = md.getColumnCount();
for (int i=1;i<=nColumns;i++){
System.out.print(md.getColumnName(i)+((i==nColumns)?"\n":"\t"));
if(i==2) System.out.print("\t");
}
while (rs.next()){
for(int i=1;i<=nColumns;i++){
System.out.print(rs.getString(i)+((i==nColumns)?"\n":"\t"));
}
}
}
catch(SQLException ex){
System.err.println(ex.getMessage()+"连数据库有问题!");
}
return rs;
}
}
输出结果为:
第二个参数为:Hello,may~
结果集列数4
BOOKID BOOKNAME PUBLISHER PRICE
001-22-23-1 jsp 应用开发详解 电子工业出版社 123
123 uml参考手册 机械工业出版社 34