i have recordset that in it contain column product and status.
for example:
Product Status
salt good
sugar bad
salt bad
sugar good
sugar good
later in the report i need to make summary based on the status, like this
summary good
product_code sum
sugar 2
salt 1
summary bad
product_code sum
sugar 1
salt 1
i'm making report in excel, and from what i read i can determine how much salt good or bad using
Collections.frequency(collection, key)
from here
so then i think i have to separate list for good and bad and then count how much salt, sugar and any other product that exist. this is how much i go now
rs = impl.showOnlyColumn(query);;
ResultSetMetaData metaData = rs.getMetaData();
int colProduct = 0;
int colStatus = 0;
String dataProd="";
String dataStat="";
Map<String, String[]> mapinData= new HashMap<String, String[]>();
//making column name on excel
int columnCount = metaData.getColumnCount();
for (int column = 1; column <= columnCount; column++) {
label = new Label(column - 1, 2, metaData.getColumnName(column));
excelSheet.addCell(label);
// check if column is product or status
String columnName = metaData.getColumnName(column).toLowerCase();
if (columnName.contains("produ")) {
colProduct = column;
} else if (columnName.contains("status")) {
colStatus = column;
}
}
//render the data
int r = 3;
while (rs.next()) {
for (int column = 0; column <= columnCount - 1; column++) {
String cellValue = (rs.getString(column + 1) == null ? "" : rs.getString(column + 1));
label = new Label(column, r, cellValue);
excelSheet.addCell(label);
if (column == colProduct) {
dataProd = cellValue;
}else if (column==colStatus) {
dataStat = cellValue;
}
}
mapinData.put(dataStat,dataProd);
r++;
}
myFirstWbook.write();
the problem is i don't know how to make an array based on the status name
mapinData.put(dataStat,how to make array here?);
then i will take the array, for counting the sum of the product with that status
if there is something that i don't describe well please tell me, really appreciate your help.