java.lang.outofmemory exception while reading excel file (xlsx) using POI

后端 未结 7 1900
死守一世寂寞
死守一世寂寞 2020-12-19 19:34

I am developing a web application which reads data from excel file (xlsx). I am using POI for reading excel sheet. The problem is when I try to read excel file, the server t

7条回答
  •  青春惊慌失措
    2020-12-19 20:26

    Improvement to your current approach could be to read around 100 lines (experiment with this figure to get optimum value) from excel and do a batch update in database. This will be more faster.

    Also you can possibly perform some optimizations in your code, move the list creation out of outer loop (loop for reading row data)

    List data = new ArrayList();

    Read contents of all the cells present in a row in a string buffer (possibly delimited with "comma") and then add it to arraylist "data"

    You are adding an object of type XSSFRow to the arraylist. There is no point in storing the whole object of excel cell. Take out its contents and discard the object.

    Later before inserting the contents in to Database you can split the delimited cell contents and perform insertion.

    Hope this helps!

提交回复
热议问题