2012-09-21 121 views
2

我已經在Oracle爲什麼字符串打印不正確?

create or replace type my_friend_list 
is 
table of 
varchar2(100); 

創建了一個用戶類型現在我已經寫它有這樣的輸出參數的過程:我在SQLDeveloper運行

PROCEDURE friends_diff_prc 
    (
    my_name IN VARCHAR2, 
    friend_i IN my_friend_list , 
    good_friend_o OUT my_friend_list , 
    best_friend_o OUT my_friend_list , 
    isSuccess   OUT NUMBER 
); 

它運行正常。

它給我列出我的好朋友和最好的朋友。

但是當我通過擴展StoredProcedure的JAVA類調用它時。

best_friend列表中正確地將來臨,但對於good_friend名單正在打印

Ljava.lang.Object;@24342434, 
Ljava.lang.Object;@243a243a, 
Ljava.lang.Object;@24402440, 
Ljava.lang.Object;@24462446 

我的Java代碼來獲取該輸出的ArrayList是這樣的:

List<String> goodfriends = Arrays.asList((String[]) results.get("good_friend_o"); 
List<String> bestfriends = Arrays.asList((String[]) results.get("best_friend_o"); 

爲什麼不給正確的結果對於好朋友?

在此先感謝。

+1

'Ljava.lang.Object; @ 24462446'表示您正在嘗試打印一個Object []'數組。你可以嘗試使用'for(Object o:(Object [])goodFriend){System.out.println(o);}'通過一個'good_friend'實例並編輯你的問題和結果? – sp00m

+0

@ sp00M我不知道爲什麼它會爲bestfriends打印正確 – vikiiii

+0

我不知道,但也許我們會發現如果您嘗試按照我的說法打印。 – sp00m

回答

0

您將答案作爲字符串數組獲取,然後存儲在列表字符串中。您無法直接將字符串[]存儲到字符串中。

您可以發佈用於提取和打印的java代碼嗎...

0

試試這個代碼。這將打印字符串

System.out.println("Printing goodfriends"); 
for (Object object : goodfriends) { 
    Object[] goodfriendsString = (Object[]) object; 
    for (Object object2 : objLocationVO) { 
    System.out.println(object2);    
    } 
} 
+0

這不是一個解決方案,而是一個貶義的步驟。所以,它應該是一個評論,而不是一個讚賞者。 – sp00m

相關問題