Win a copy of Murach's Python Programming this week in the Jython/Python forum!
    Bookmark Topic Watch Topic
  • New Topic

Java Heap Space Error, OutofMemory Exception while writing large data to excel sheet.  RSS feed

 
Prashant Kadake
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Report post to moderator
Hi,
I am getting Java Heap Space Error while writing large data from database to an excel sheet.
I dont want to use JVM -XMX options to increase memory.

Following are the details:
1) I am using org.apache.poi.hssf api for excel sheet writing.
2) JDK version 1.5
3) Tomcat 6.0
Code i have wriiten works well for around 23 thousand records, but it fails for more than 23K records.

Following is the code:



Please help me with the solution.
 
Greg Charles
Sheriff
Posts: 3014
12
Firefox Browser IntelliJ IDE Java Mac Ruby
  • Mark post as helpful
  • send pies
  • Report post to moderator
That's a lot of code, and your adherence to Hungarian notation makes it, for me, all but unreadable. Fortunately, your basic problem is on line 2, where you have something like xyzzyxr!#$fetchAll%&*xqy. Buried in the nonsense of notation, are the words "fetch all". What you need to do is redesign your program so you can work with a database result set. That way you can read records one by one from the database (actually in chunks, but those details will be handled by the driver). You can then transform each record as needed and write it out to your file. You thus avoid having the entire representation of the data in core memory all at the same time.
 
Joe Ess
Bartender
Posts: 9406
12
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Report post to moderator
Please do not post the same question more than once. It causes confusion and duplication of effort as our community tries to help everyone.
 
    Bookmark Topic Watch Topic
  • New Topic
Boost this thread!