i get the result from a query using:
String query = "select a from TABLE a";
Query q = em.createQuery(query);
List<Type> res = q.setMaxResults(5).getResultList();
how do i print the list out using a loop? im trying this but i have to manually specify the value to print.
Iterator<SplashPage> i = resultList.iterator();
while (i.hasNext())
{
System.out.println(i.next().adEndDate);
System.out.println(i.next().adStartDate);
System.out.println(i.next().compPAL);
System.out.println(i.next().compSymbol);
System.out.println(i.next().compUrl);
}
^also from this some of values are not known?! it throws a NoSuchElementException as well
once i get the results i pass the list to a javascript function to prin out on a html page, but everything comes out “undefined” 🙁
calling
nextlike that incrememts the iterator with each call. Since you have 5printlncalls, each time through the loop you go over 5 different items.You want
You also can define a
toStringmethod on your entity class and use that, to cut down the number of prints….