retrieve values of rows (from Postgresql) in a list in java -
i used hashmap handling resultset queried postgresql using code suggested rht
public list resultsettoarraylist(resultset rs) throws sqlexception{ resultsetmetadata md = rs.getmetadata(); int columns = md.getcolumncount(); arraylist list = new arraylist(50); while (rs.next()){ hashmap row = new hashmap(columns); for(int i=1; i<=columns; ++i){ row.put(md.getcolumnname(i), rs.getobject(i)); } list.add(row); } return list; }
i did beacuse wanted shuffle collection afterwards.
now each row that:
{owner=22172613@n07, count=2}
i not know how can for/each loop retrieve each owner id , corresponding number !!
so have arraylist
each element of hashmap
contains in key column names of results , in values values of columns.
a loop following:
//call method resultsettoarraylist here list<map> list = (list<map>) resultsettoarraylist(rs); //loop list for(map r: list) { system.out.println("row data: "); final iterator columniterator = r.keyset().iterator(); while(columniterator.hasnext()) { final object next = columniterator.next(); system.out.println("\tcolumn: " + next + " / value: " + r.get(next)); } }
Comments
Post a Comment