Pivot a Database Result Set
Get a Pivot List from a JDBC ResultSet.
Javadoc available at https://www.javatapas.com/docs/javatapas/sql/PivotDatabaseResultSet.html
private List<List<String>> pivotDatabaseResultSet(ResultSet rset) throws SQLException {
List<List<String>> pivotList = new ArrayList<>();
ResultSetMetaData rsmd = rset.getMetaData();
for (int i = 1; i <= rsmd.getColumnCount(); i++){pivotList.add(new ArrayList<String>());}
int rowIdx = 0;
while (rset.next()){
for (int i = 1; i <= rsmd.getColumnCount(); i++) {
String cell = rset.getString(i);
if (cell == null || rset.wasNull()){cell = "NULL";}
pivotList.get(i - 1).add(cell);
}
}
return pivotList;
}