【发布时间】:2012-01-09 12:26:59
【问题描述】:
我的 Java 代码调用 Oracle DB 中的存储过程并返回带有一些字段的对象。 当我从对象中找出属性时 - 我的字符串有问题。字符串变为'???' (3个问号)不应该是这样! (整数返回OK)
我在数据库上测试了我的存储过程 - 它运行良好。
我用调用数据库的小型本地主程序测试了我的 Java 代码 - 它运行良好。 (数据库的连接直接与 DriverManager.getConnection("jdbc:oracle:thin:@......); )
当我在我的大项目中使用我的存储过程通过 weblogic 连接到数据库时出现了问题。
当我使用 WebLogic 时,您知道如何从数据库中获取正确的字符串吗?
Oracle 代码:
PROCEDURE SearchOrder (InWoArr IN WoTab,
OutWoAccStat OUT WoAccStatTab) as
outRec WoAccStatType;
wo number(10);
acc number(10);
stat varchar2(2);
begin
OutWoAccStat := WoAccStatTab();
for i in InWoArr.FIRST .. InWoArr.LAST loop
OutWoAccStat.EXTEND;
begin
select work_order_number,account_number,' '
into wo,acc,stat
from table1
where work_order_number=InWoArr(i);
....
outRec := WoAccStatType(wo,acc,stat);
OutWoAccStat(i) := outRec;
exception
when no_data_found then
outRec := WoAccStatType(InWoArr(i),0,' ');
OutWoAccStat(i) := outRec;
end;
end loop;
end SearchOrder;
//200 个数组
create or replace type poldev_dba.WoAccStatTab as VARRAY(200) of WoAccStatType
//数组类型
create or replace type poldev_dba.WoAccStatType as object (work_order_number number(10), account_number number(10), wo_status varchar2(2))
//Java代码:
//Store Procedure Name
CallableStatement cs = (CallableStatement) con.prepareCall("{ call spp.SearchOrder( ?, ? )}");
//input:
cs.setArray(1,woInput);
//Output:
cs.registerOutParameter(2,OracleTypes.ARRAY,"WOACCSTATTAB");
//Run the query...
cs.execute();
//Retrieve Array:
woAccArray = (ARRAY)cs.getArray(2);
woAccRecs = (Object[])woAccArray.getArray();
int wo = 0;
int acc = 0;
String stat;
for (int i = 0; i < woAccRecs.length; i++) {
/* Since we don't know the type of the record, get it into STRUCT !! */
STRUCT woAccRec = (oracle.sql.STRUCT)woAccRecs[i];
/* Get the attributes - nothing but the columns of the table */
Object[] attributes = woAccRec.getAttributes();
/* attribute 0 - work order */
wo = Integer.parseInt("" + attributes[0]);
/* attribute 1 - account number */
acc = Integer.parseInt("" + attributes[1]);
/* attribute 2 - status */
stat = (String) attributes[2];
/*PROBLEM!!!! stat returned value '???'*/
System.out.println("wo = " + wo + ",acc = " + acc +", status = "+stat);
【问题讨论】:
-
字符串应该是什么?我怀疑 显示 字符串时存在编码和字体问题。尝试调试您的程序并在从存储过程返回时检查字符串的内容,以了解它是否真的 ???
-
字符串是“C”或“O”。没有工作。我将其更改为“0”或“”-仍然无效。 (通过连接到数据库的小主程序,它可以正常工作并返回“C”和“O”)
-
你试过用 NVARCHAR2 代替 VARCHAR2 吗?
-
谢谢大家!!! SWeko 是对的。在我将变量从 varchar2 更改为 nvarchr2 后开始工作!!!
标签: java stored-procedures jdbc oracle10g weblogic