java - How to put data into HashMap<key, Object> -
i new programming. have program iterates excel file , put values hashmap hashmapbut object in hash map has last record. i'll post code , may can tell me mistakes, or better yet post code how should done. please help, stuck here.
my excel file:
doc seq acc status notes 1111 2 account test value1 22222 3 account test2 value2
my object ....
public class account{ int docnumber; int docsequence; string docacccode; string docstatus; string docnotes; //getters , setters bellow ...... }
my iterate method...
public void readfile() throws ioexception{ inputstream excelfiletoread = new fileinputstream(inputfile); xssfworkbook wb = new xssfworkbook(excelfiletoread); xssfsheet sheet = wb.getsheetat(0); xssfrow row = null; xssfcell cell = null; int recordnumber = 0; iterator rows = sheet.rowiterator(); while (rows.hasnext()){ row=(xssfrow) rows.next(); int rownum = row.getrownum(); int cellnum = 0; if(rownum != 0){ iterator cells = row.celliterator(); while (cells.hasnext()){ cell=(xssfcell) cells.next(); switch(cellnum){ case 0: docmap.setdocnumber((int)cell.getnumericcellvalue()); break; case 1: docmap.setdocsequence((int)cell.getnumericcellvalue()); break; case 2: docmap.setdocacccode(cell.getstringcellvalue()); break; case 3: docmap.getdocstatus(cell.getstringcellvalue()); break; case 4: docmap.getdocnotes(cell.getstringcellvalue()); } cellnum ++; } // docmap overwrites it's self , has last record only. records.put(recordnumber, docmap); recordnumber ++; } } }
it seems using single instance of docmap object. need new docmap in while loop.
Comments
Post a Comment