日期:2014-05-17  浏览次数:21239 次

java如何读取plsql的对象数组,抛出异常:无效的名称模式
创建包:traveler_assistance_package
创建自定义数组:TYPE lgn IS table OF NVARCHAR2(20);  
存储过程:
 procedure country_languages
  ( country_n in NVARCHAR2, 
  c_n out NVARCHAR2,
  l_ns_out out lgn,
  ofls_out out lgn  
  );

------------------------------------------
在oracle端调用这个存储过程是没有问题的,但是在jsp中用java调用就出错:

java.sql.SQLException: 无效的名称模式: FOF.LGN

------------------------------------------------------
我的java代码是这样的:

String procedure = "{call traveler_assistance_package.country_languages(?,?,?,?) }";

OracleCallableStatement cstmt=(OracleCallableStatement)con.prepareCall(procedure);
cstmt.setString(1,countryname); 

 cstmt.registerOutParameter(2,oracle.jdbc.OracleTypes.VARCHAR);//输出参数 
 cstmt.registerOutParameter(3,oracle.jdbc.OracleTypes.ARRAY,"LGN");
 cstmt.registerOutParameter(4,oracle.jdbc.OracleTypes.ARRAY,"LGN");//换成 "traveler_assistance_package.LGN"也是不行
 cstmt.execute();
 //traveler_assistance_package.lgn");//,"VARCHAR2_TABLE");
String c_n=cstmt.getString(2); 
ARRAY array = cstmt.getARRAY(3);
String[] splArray=(String[])array.getArray();

ARRAY array1 = cstmt.getARRAY(4);
String[] oflArray=(String[])array1.getArray();

----------------------------------

这段java代码哪里错了啊,怎么修改啊~~~~(>_<)~~~~ 
高手帮帮忙吧~~


------解决方案--------------------
顶啊 生死攸关!
------解决方案--------------------
参考一下这个
------解决方案--------------------
CREATE OR REPLACE TYPE USERSEQID_ARRAY IS VARRAY(50000) OF NUMBER(9)
CREATE OR REPLACE TYPE USERNAME_ARRAY AS VARRAY(32) of varchar(32)

CREATE OR REPLACE procedure make_logincard_pro (
p_cardsuitcode in varchar,
p_userseqidArr out USERSEQID_ARRAY ,
p_usernameArr out USERNAME_ARRAY 
)
IS
v_addedtime date:= sysdate;
BEGIN
FOR ii IN 1 .. 10 LOOP
IF p_userseqidArr IS NULL THEN
p_userseqidArr := USERSEQID_ARRAY(ii);
ELSE
p_userseqidArr.EXTEND; --超过数组定义大小(50000)将抛出异常
p_userseqidArr(ii) := ii;
END IF;

IF p_usernameArr IS NULL THEN
p_usernameArr := USERSEQID_ARRAY(ii || ''TT'');
ELSE
p_usernameArr.EXTEND; --超过数组定义大小(32)将抛出异常
p_usernameArr(ii) := ii || ''TT'';
END IF;
END LOOP

END make_logincard_pro ;
 

 JAVA调用存储过程:
Connection con = session.connection();
java.sql.CallableStatement cst = con
prepareCall("call CNBT.test_pro(?,?,?)");
cst.setString(1, cardSuitCode);
cst.registerOutParameter(2, OracleTypes.ARRAY,"USERSEQID_ARRAY");
cst.registerOutParameter(3, OracleTypes.ARRAY,"USERNAME_ARRAY");

java.sql.Array userSeqIdArr = cst.getArray(2);
java.sql.Array userNameArr = cst.getArray(3);

--------给你参考下。。。我认为应该是is table of不能当array使用,我明天查下java和oracle的api看看。。。。