First, I had a problem with getting the data from the Database, it took too much memory and failed. I\'ve set -Xmx1500M and I\'m using scrolling ResultSet so that was taken care
You are assembling the complete file in memory: what you should be doing is writing the data directly to the file.
Additionally, you might consider using a proper XML API rather than assembling XML as a text file. A short tutorial is available here.