我在Java中的代码调用Oracle DB中的存储过程并返回带有一些字段的对象。 当我从对象中找到属性时 - 我对字符串有问题。字符串成为' ???' (3个任务标记)它不应该是那个! (整数返回OK)
我在数据库上测试了我的存储过程 - 它工作得很好。
我使用调用数据库的小型本地主程序测试了我的Java代码 - 它运行良好。 (DB与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);
答案 0 :(得分:0)
问题出在其他地方。 Oracle DB和DB驱动程序都不会将结果列替换为???
。在产品代码中搜索此字符串,了解其使用原因。