2014-11-21 127 views
1

我得到StudentIds的列表作爲List<String>無法打印oracle.sql.ARRAY

我將其轉換成一個String[]後來,

String[] studentIdArray = null; 
if (list!= null) { // StudentList 
studentIdArray = list.toArray(new String[list.size()]); // printed studentIdArray and print the values. its fine 
} 

然後,一個arrayDescriptor聲明映射Java的String[]爲RAW的PLSQL表定義爲STUDENT_ID_TYPE

ArrayDescriptor arrayDescriptor = ArrayDescriptor.createDescriptor("STUDENT_ID_TYPE", connection); 

現在,我得到了oracle.sql.ARRAY出來,

ARRAY studentArray = new ARRAY(arrayDescriptor, connection, studentIdArray); 

無法找到如何打印在studentArray值,雖然當我打印studentArray.length(),它返回爲1,這 我覺得是正確的。 BUt當這個數組傳遞給我的PLSQL過程時,我得到自定義異常。

編輯:當我使用轉儲(),它只是轉儲爲元素[0] = [B @ 438620c7

回答

1

爲了在studentArray打印值可以首先將數據作爲基準[]然後轉換該基準值由數據[i] .stringValue()字符串。

Datum[] datumArr = studentArray.getOracleArray(); 

for (Datum datum: datumArr) 
{ 
    System.out.println(datum.stringValue()); 
} 
+0

認識到,將檢查並標記爲答案 – spiderman 2014-11-28 14:01:20

+0

讓我們來看看它是如何工作:) – Willmore 2014-11-28 14:48:24

+0

這就像一個魅力,太棒了!謝謝@MariusŽilėnas – spiderman 2014-12-09 19:47:37