当前位置: 技术问答>java相关
包的调用,为什么找不到包中的函数?
来源: 互联网 发布时间:2015-08-16
本文导语: 编译已经通过,执行错误:PLS-00221: 'SELECTCODEDATA' 不是过程或尚未定义。但包中肯定定义了SELECTCODEDATA,为什么? import java.sql.*; import java.io.*; import oracle.jdbc.driver.*; class test { public static void main(String args[]) throw...
编译已经通过,执行错误:PLS-00221: 'SELECTCODEDATA' 不是过程或尚未定义。但包中肯定定义了SELECTCODEDATA,为什么?
import java.sql.*;
import java.io.*;
import oracle.jdbc.driver.*;
class test
{
public static void main(String args[]) throws SQLException
{
DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
Connection conn = DriverManager.getConnection("jdbc:oracle:thin:@10.1.1.20:1521:ddl", "airext", "password");
CallableStatement call = conn.prepareCall("{call PACKAGE_FLIGHT_QUERY.SELECTCODEDATA}");
call.registerOutParameter(1, OracleTypes.CURSOR);
call.execute();
ResultSet rst = (ResultSet)call.getObject(1);
while(rst.next())
{
System.out.println("结果1: "+rst.getInt(1));
System.out.println("结果2: "+rst.getString(2));
}
}
}
包的定义如下:
CREATE OR REPLACE PACKAGE PACKAGE_FLIGHT_QUERY AS
-- TYPE FLIGHTRESULT IS RECORD (SEATS TB_CITY_OUTPORT_DETAIL_FNL.SEATS%TYPE,SEATED TB_CITY_OUTPORT_DETAIL_FNL.SEATED%TYPE,RATE NUMBER(3,2),FLIGHTED TB_CITY_OUTPORT_DETAIL_FNL.SEATED%TYPE);
TYPE CITYRESULT IS RECORD (CITY_CODE TB_CITY_AIRPORT.CITY_CODE%TYPE,CNAME TB_CITY_AIRPORT.CNAME%TYPE);
TYPE AIRCODERESULT IS RECORD (AIR_CODE TB_AIR_LINE.AIR_CODE2%TYPE,CNAME TB_AIR_LINE.CNAME%TYPE);
TYPE CITYRCTYPE IS REF CURSOR RETURN CITYRESULT;
TYPE AIRCODERCTYPE IS REF CURSOR RETURN AIRCODERESULT;
FUNCTION SELECTCITYDATA RETURN CITYRCTYPE;
FUNCTION SELECTCODEDATA RETURN AIRCODERCTYPE;
END PACKAGE_FLIGHT_QUERY;
/
CREATE OR REPLACE PACKAGE BODY PACKAGE_FLIGHT_QUERY AS
FUNCTION SELECTCITYDATA RETURN CITYRCTYPE IS RC CITYRCTYPE; --返回城市列表
EXCSQLSTR1 VARCHAR2(1000);
BEGIN
OPEN RC FOR SELECT TRIM(CITY_CODE) CITY_CODE,TRIM(CNAME) CNAME FROM TB_CITY_AIRPORT ORDER BY TRIM(CNAME);
RETURN RC;
END;
FUNCTION SELECTCODEDATA RETURN AIRCODERCTYPE IS RC AIRCODERCTYPE; --返回航空公司列表
EXCSQLSTR1 VARCHAR2(1000);
BEGIN
OPEN RC FOR SELECT AIR_CODE2 AIR_CODE,CNAME FROM TB_AIR_LINE ORDER BY ORD;
RETURN RC;
END;
END PACKAGE_FLIGHT_QUERY;
/
import java.sql.*;
import java.io.*;
import oracle.jdbc.driver.*;
class test
{
public static void main(String args[]) throws SQLException
{
DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
Connection conn = DriverManager.getConnection("jdbc:oracle:thin:@10.1.1.20:1521:ddl", "airext", "password");
CallableStatement call = conn.prepareCall("{call PACKAGE_FLIGHT_QUERY.SELECTCODEDATA}");
call.registerOutParameter(1, OracleTypes.CURSOR);
call.execute();
ResultSet rst = (ResultSet)call.getObject(1);
while(rst.next())
{
System.out.println("结果1: "+rst.getInt(1));
System.out.println("结果2: "+rst.getString(2));
}
}
}
包的定义如下:
CREATE OR REPLACE PACKAGE PACKAGE_FLIGHT_QUERY AS
-- TYPE FLIGHTRESULT IS RECORD (SEATS TB_CITY_OUTPORT_DETAIL_FNL.SEATS%TYPE,SEATED TB_CITY_OUTPORT_DETAIL_FNL.SEATED%TYPE,RATE NUMBER(3,2),FLIGHTED TB_CITY_OUTPORT_DETAIL_FNL.SEATED%TYPE);
TYPE CITYRESULT IS RECORD (CITY_CODE TB_CITY_AIRPORT.CITY_CODE%TYPE,CNAME TB_CITY_AIRPORT.CNAME%TYPE);
TYPE AIRCODERESULT IS RECORD (AIR_CODE TB_AIR_LINE.AIR_CODE2%TYPE,CNAME TB_AIR_LINE.CNAME%TYPE);
TYPE CITYRCTYPE IS REF CURSOR RETURN CITYRESULT;
TYPE AIRCODERCTYPE IS REF CURSOR RETURN AIRCODERESULT;
FUNCTION SELECTCITYDATA RETURN CITYRCTYPE;
FUNCTION SELECTCODEDATA RETURN AIRCODERCTYPE;
END PACKAGE_FLIGHT_QUERY;
/
CREATE OR REPLACE PACKAGE BODY PACKAGE_FLIGHT_QUERY AS
FUNCTION SELECTCITYDATA RETURN CITYRCTYPE IS RC CITYRCTYPE; --返回城市列表
EXCSQLSTR1 VARCHAR2(1000);
BEGIN
OPEN RC FOR SELECT TRIM(CITY_CODE) CITY_CODE,TRIM(CNAME) CNAME FROM TB_CITY_AIRPORT ORDER BY TRIM(CNAME);
RETURN RC;
END;
FUNCTION SELECTCODEDATA RETURN AIRCODERCTYPE IS RC AIRCODERCTYPE; --返回航空公司列表
EXCSQLSTR1 VARCHAR2(1000);
BEGIN
OPEN RC FOR SELECT AIR_CODE2 AIR_CODE,CNAME FROM TB_AIR_LINE ORDER BY ORD;
RETURN RC;
END;
END PACKAGE_FLIGHT_QUERY;
/
|
在用包里面类的方法时,首先要实例化类,然后通过对象.取你的方法,就可以了。