Trying to put the Result set Values inside a Map

Viewed 1383

I'm trying to put the Result Set (DB Query Values) inside a LinkedHashMap>.

Every Iteration of row. The value is getting overriden while putting into DBMap.

<LinkedHashMap<String, String>> rowData = new LinkedHashMap<>();
<LinkedHashMap<Integer, LinkedHashMap<String, String>>> dbData = new LinkedHashMap<>();
while (rset.next()) {

                    for (int col = 1; col < countCol+1; col++) {
                        String colname =rset.getMetaData().getColumnName(col);
                        rowData.put(colname, rset.getString(col));
                    }
                    int rowV = rset.getRow();
                    dbData.put(rowV, rowData);
}

This code is giving me the map of only the last row of the result set for all the keys in dbData Map.

2 Answers
Related