[英]String returned from oracle stored procedure to Java with '???'
我用Java編寫的代碼調用Oracle DB中的存儲過程,並返回帶有某些字段的對象。 當我從對象中找到屬性時-字符串有問題。 字符串變為“ ???” (3個問號),而不是那樣! (整數返回確定)
我在數據庫上測試了存儲過程-效果很好。
我用小的本地主程序測試了我的Java代碼,該程序調用了DB,並且運行良好。 (DB的連接直接通過DriverManager.getConnection(“ jdbc:oracle:thin:@ ......);)
當我在通過Weblogic連接到DB的大項目中使用存儲過程時,問題就來了。
當我使用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);
問題出在其他地方。 Oracle DB和DB驅動程序都不會將結果列替換為???
。 在產品代碼中搜索該字符串,以了解使用原因。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.