2014-11-21 82 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