Well, that must be an easy one but I can’t find the solution anywhere. And I am still not enough comfortable using Java to figure out the way to do it.
So far, I am able to loop through a ResultSet and I’m quite proud of myself already.
I would like a List so I could simply loop through it and then call something like myRow.get('ColumnName');.
Also, there MIGHT another data type instead of a Hashtable to store the key/value. Any tips?
Thank you very much!
myRow.get('ColumnName');is already inResultSet, see getObject(String columnLabel). Now, one difference betweenResultSetandMapis that aResultSetis not (always) random access. Once you go past a row, usingResultSet.next(), it may not allow you to “rewind” to the previous row. There is good reason for this: the number of elements in ReusltSet can be arbitrarily large and the memory requirement on a list of map would be prohibitive.If you do decide to convert it to a
List<Map<String, Object>>then you should create your own implementation of both theListand theMap, such that aMap<String /*columnName*/, Integer /*Index*/>is gives the index of a column-name in each array. I am speaking from experience, I had to change an implementation where a iterating through list of column names was too expensive.