JAVA 调用 Oracle 存储过程的问题

RickyLoveCoding 2010-01-06 04:59:09
我使用java调用Oracle包中的存储过程,返回值为自定义TYPE的列表
将列表中元素的变量值取出,用println打出来,显示的都是3个问号
如下情况:
???
???
???
请教各位是哪里出了差错。
注:在Oracle中直接调用存储过程时,返回值正确。
查询结果的size大小正确,但值均为???
Oracle版本11G,IDE:MyEclipse7.1
OS:英文版的2008
是不是编码的问题,该怎样解决?谢谢

存储过程如下:
CREATE OR REPLACE
PACKAGE BODY "TRAVELER" AS

procedure 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;
}
...全文
99 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
Landor2004 2010-01-09
  • 打赏
  • 举报
回复
oracle数据库安装的是英文版的吗?

在java中用String str = new String(str.getBytes("ISO8859-1","gbk"))来转码吧

查看oracle字符集
select * from sys.props$;其中NLS_CHARACTERSET就是当前oracle字符集

50,549

社区成员

发帖
与我相关
我的任务
社区描述
Java相关技术讨论
javaspring bootspring cloud 技术论坛(原bbs)
社区管理员
  • Java相关社区
  • 小虚竹
  • 谙忆
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧