tags:

views:

79

answers:

2

Hello,

Regarding to this image: link text

I have an object, 'rezultat', which has getters and setters. I wanna set for 'cli' attribute ( rezultat.setCli(String .....) ), and as string parameter it should be that m_objArray[0], so 'ADSL22675....' from that image. Expanding m_objArray there are 19 attributes i need to set for the 'rezultat' object attributes. But i don't know how to access them.

Array o = ocs.getArray(1);
Object[] obj = (Object[])o.getArray();
rezultat = new ListOfMdfTab();
for (int i = 0; i < obj.length; i++)
{
rezultat.setCli ((String)obj[0].<what>?); //i need here that m_objArray[0].
}

'ocs' is an OracleCallableStatament object type, so i need Array o = ocs.getArray(1); because that 1 index is the out parameter which is a complx type. Please help. Thanks!

+2  A: 

This statement will return a String or will throw a clasCastException if the Object is not a string:

(String)obj[0]

If you're not sure if it is a String you could use

obj[0].toString()

OR

String.valueOf(obj[0])

Which will handle nulls more elegantly

souLTower
From the picture OP linked, `obj[0]` is a `STRUCT` (whatever that means). Within it there's a `Object[] m_objArray` which contains `String`. At least that's how I'm reading it.
polygenelubricants
I tried with obj[0].toString() and it returned oracle.sql.STRUCT. So, the type. I need the values from m_objArray, that node contains 19 elements, whose values i need (see that image).
Roger22
Yes, true: rom the picture OP linked, obj[0] is a STRUCT (whatever that means). Within it there's a Object[] m_objArray which contains String. At least that's how I'm reading it. And how can access m_objArray's values?
Roger22
+1  A: 

STRUCT is an oracle class that implements the java.sql.Struct interface. This interface offers a getAttributes() method.

It's worth a try calling this method and hoping for the best, that the array that is returned is equal to the internal m_objArray.

In Java code:

rezultat.setCli(((java.sql.Struct)obj[0]).getAttributes()[0].toString()); 
Andreas_D
Worked, thanks!
Roger22
@Roger: you should then mark this answer accepted. Also see http://stackoverflow.com/faq
BalusC