I'm making query using native sql with following code
private <T> List<T> executeNativeQuery(String queryString,
Map<String, Object> param, Class<T> clazz) {
Query query = entityManager.createNativeQuery(queryString);
if (param != null && param.size() > 0) {
for (Map.Entry<String, Object> entry : param.entrySet()) {
query.setParameter(entry.getKey(), entry.getValue());
}
}
List<T> resultList = query.getResultList();
return resultList;
}
And getting following database result.
VendorName | IncidentID | IncidentStatus | IncidentDate
-------------------------------------------------------
XYZ | 100 | Open | 02-JUN-2011
ABC | 101 | Closed | 03-JUN-2011
MNP | 102 | Open | 01-JUN-2011
LPQ | 103 | Open | 01-APR-2011
To iterate this result, i'm using following approach
Iterator iter=resultList.iterator();
while (iter.hasNext()) {
Object[] result= (Object[]) iter.next();
System.out.println("Vendor Name-->" +result[0]);
}
Is there any better way to iterate through the list ?
resultList? You are already castingiter.next()toObject[], so it must be an Iterator of either Object[] or some other array type, right?