我使用java调用Oracle包中的存储过程,返回值为自定义TYPE的列表
将列表中元素的变量值取出,用println打出来,显示的都是3个问号
如下情况:
???
???
???
请教各位是哪里出了差错。
注:在Oracle中直接调用存储过程时,返回值正确。
查询结果的size大小正确,但值均为???
Oracle版本11G,IDE:Eclipse

解决方案 »

  1.   

    存储过程如下:
    CREATE OR REPLACE 
    PACKAGE BODY "TRAVELER" ASprocedure country_demographics (c_name in WF_COUNTRIES.COUNTRY_NAME%TYPE,c_descriprion1 out
    country_info1_record_type) is
    c_descriprion2 COUNTRY_INFO1_RECORD_TYPES;
    begin
    c_descriprion2 :=NEW COUNTRY_INFO1_RECORD_TYPES(' ',' ',' ',' ', ' ',' ');
    select country_name,location,capital,population,airports,climate
    into c_descriprion2.country_name , c_descriprion2.location , c_descriprion2.capital , c_descriprion2.population,c_descriprion2.airport,c_descriprion2.climate
    from WF_COUNTRIES
    WHERE country_name = c_name;
    --DBMS_OUTPUT.put_line('国家:'||c_descriprion2.country_name);
    --DBMS_OUTPUT.put_line('位置:'||c_descriprion2.location);
    --DBMS_OUTPUT.put_line('首都:'||c_descriprion2.capital);
    --DBMS_OUTPUT.put_line('人口:'||c_descriprion2.population);
    --DBMS_OUTPUT.put_line('机场:'||c_descriprion2.airport);
    --DBMS_OUTPUT.put_line('气候:'||c_descriprion2.climate);
    c_descriprion1 := new COUNTRY_INFO1_RECORD_TYPE();
    c_descriprion1.extend();
    c_descriprion1(1) := c_descriprion2;
    end country_demographics;java代码如下
       public static COUNTRY_INFO1_RECORD_TYPES getCountry_demographics(String c_name) {
            Connection conn = null;
            conn = instance.getConnection();
            COUNTRY_INFO1_RECORD_TYPES country_info1 = new COUNTRY_INFO1_RECORD_TYPES();
            try {
                conn.setAutoCommit(false);
                OracleCallableStatement cst = (OracleCallableStatement) conn.prepareCall("{call  traveler.country_demographics(?,?)}");
                cst.setString(1, c_name);
                cst.registerOutParameter(2, OracleTypes.ARRAY, "COUNTRY_INFO1_RECORD_TYPE");
                cst.execute();
                
                ARRAY RacRecordArray = (ARRAY) cst.getARRAY(2);
                Datum[] datas = RacRecordArray.getOracleArray();
                System.out.println(datas.length);
                for (int index = 0; index < datas.length; index++) {
                    if (datas[index] != null) {
                        Datum[] regionAttributes = ( (STRUCT) datas[index]).getOracleAttributes();
                        country_info1.setCountry_name(regionAttributes[0].stringValue());
                        country_info1.setLocation(regionAttributes[1].stringValue());
                        country_info1.setCapital(regionAttributes[2].stringValue());
                        country_info1.setPopulation(regionAttributes[3].stringValue());
                        country_info1.setAirport(regionAttributes[4].stringValue());
                        country_info1.setClimate(regionAttributes[5].stringValue());
                        System.out.println(country_info1.getCountry_name());
                    }
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
            return country_info1;
        }
      

  2.   

    以前做JSP的时候,JAVA+MYSQL的时候有出现这样的情况,设置编码就可以了,你去JAVA编程区问问看
      

  3.   

    编码问题,楼主看看你的oracle编码,java默认编码都是unicode的,如果你的数据库编码是GBK或者latin之类的,需要转码比如数据库里存放的是GBK,需要2步转换, str=new String(rs.getBytes(1),"GBK"); 再str=new String(str.getBytes("UTF-8"),"GBK"),才可以正确显示中文。
    如果是UTF8还出这种问题,那么修改你的IDE项目右键->info->text file encodiing改为UTF8再试试看,如果还不行,灵异事件:
    SQL>
    select userenv('language')from dual;USERENV('LANGUAGE')
    -----------------------------------------------
    SIMPLIFIED CHINESE_CHINA.UTF8SQL>
      

  4.   

    以前做JSP的时候,JAVA+MYSQL的时候有出现这样的情况,设置编码就可以了,你去JAVA编程区问问看
      

  5.   


    但我直接写SQL语句来执行的话,返回值能正常显示,唯独调用过程时有此状况。
      

  6.   

    我的数据库是GBK编码的,用你的方法解决问题了,谢谢 :-)