我在Java中的代码调用Oracle DB中的存储过程,并返回带有一些字段的对象。 当我找到对象的属性 - 我有问题的字符串。该字符串变成'???' (3个任务标记),它不应该是那个! (整数返回OK)使用'???'从Oracle存储过程返回给Java的字符串
我在DB上测试了我的存储过程 - 它运行良好。
我使用调用数据库的小本地主程序测试了我的Java代码 - 它运行良好。 (数据库直接连接到DriverManager.getConnection(“jdbc:oracle:thin:@ ......);)
问题出在当我在我的大项目中使用我的存储过程连接到。数据库与WebLogic
你知道如何从数据库得到正确的字符串时,我与WebLogic工作
甲骨文代码:
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') – user1072865
您是否尝试过使用NVARCHAR2而不是VARCHAR2? – SWeko