• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

Help!! - java.lang.OutOfMemoryError

 
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am trying to generate an XML string from a table with 13160 rows in the result set.
I checked the archives and found this helpful discussion: http://www.javaranch.com/ubb/Forum3/HTML/000465.html
So I tried to implement the same solution, but it's not working.
The code itself is somewhat long. I've posted it at:
http://y42.briefcase.yahoo.com/bc/iamsanjayonly/vwp2?.tok=bc J5XF7AtegBHF8g&.dir=/Code&.dnm=AllDataXML.java&.src=bc
Here are some relevant snippets:


[This message has been edited by Sanjay Anand (edited April 30, 2001).]
 
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Have you tried boosting the memory used by the VM? Try adding this command line switch -Xmx128m -Xms32m. These are only supported by Sun.
David
Sun Certified Programmer for the Java2 Platform
 
Sanjay Anand
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for your reply. I've tried to do this but where do I do it? I am running this process in a servlet that sits on tomcat on the solaris platform. I've been through the documentation but am still thoroughly confused.
Any help would be appreciated.
Thanks
Sanjay
 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Change the java startup command in tomcat.bat
------------------
Balaji Iyer,
System Architect,
Net4nuts.com
Ahmedabad
"If you want to make God Laugh, Tell HIM your plans !! "
 
Ranch Hand
Posts: 1879
MySQL Database Suse
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
stmt = con.createStatement();
CustResults = stmt.executeQuery(q);
while(CustResults.next())
{
h++;
}
this code snippet looks like you are just counting. why don't you use the count function so you don't have to iterate through so many results? If your query is "select id, name from emp where name like 'something'", you can change it to:
[code]
stmt = con.createStatement();
CustResults = stmt.executeQuery("select count(*) from emp where name like 'something'");
if (CustResults.next())
{
h=CustResults.getInt(1);
}
else
{
....
[\code]
the above may save some time and memory
Jamie
 
Sanjay Anand
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Actually in this snippet I'm checking to see if the resultset is null or not. I've been told that the comparison:
if (CustResults.next())
actually moves the resultset cursor up one count and you therefore lose the first set of data. I have not confirmed this and simply started implementing the suggested solution of moving through the resultset twice.
It seems inelegant but it does work. Any other suggestions?
Thanks for the renewed attention to this topic. I have since cleaned up other parts of my code and actually moved to JRun rather than Tomcat and no longer have this problem
Sanjay
 
Jamie Robertson
Ranch Hand
Posts: 1879
MySQL Database Suse
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Actually in this snippet I'm checking to see if the resultset is null or not. I've been told that the comparison:
if (CustResults.next())
actually moves the resultset cursor up one count and you therefore lose the first set of data. I have not confirmed this and simply started implementing the suggested solution of moving through the resultset twice.
It seems inelegant but it does work. Any other suggestions?
Thanks for the renewed attention to this topic. I have since cleaned up other parts of my code and actually moved to JRun rather than Tomcat and no longer have this problem
Sanjay[/B]


the following will do the same thing:

the above works the same as the code that you have posted except it only loops through the resultset once.
Hope that speeds it up a bit,
Jamie
 
Sanjay Anand
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks, Jamie for the input. Your solution, however, throws a nullpointer exception when you try to get a null result from the result set and then append it to a StringBuffer. It was precisely this exception that sent me scrambling to check for null through comparison.
Sanjay
 
It is an experimental device that will make my mind that most powerful force on earth! More powerful than this tiny ad!
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic