wood burning stoves 2.0*
The moose likes JDBC and the fly likes Help!! - java.lang.OutOfMemoryError Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Help!! - java.lang.OutOfMemoryError" Watch "Help!! - java.lang.OutOfMemoryError" New topic
Author

Help!! - java.lang.OutOfMemoryError

Sanjay Anand
Ranch Hand

Joined: Apr 03, 2001
Posts: 42
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).]
David Freels
Ranch Hand

Joined: Feb 01, 2001
Posts: 102
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

Joined: Apr 03, 2001
Posts: 42
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
balaji iyer
Greenhorn

Joined: Jul 18, 2001
Posts: 3
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 !! "


Balaji Iyer,<BR>System Architect,<BR>Net4nuts.com<BR>Ahmedabad<BR>"If you want to make God Laugh, Tell HIM your plans !! "
Jamie Robertson
Ranch Hand

Joined: Jul 09, 2001
Posts: 1879

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

Joined: Apr 03, 2001
Posts: 42

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

Joined: Jul 09, 2001
Posts: 1879

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

Joined: Apr 03, 2001
Posts: 42
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Help!! - java.lang.OutOfMemoryError
 
Similar Threads
Need inputs: Failed SCJD
returning a connection
Read Error: String index out of range: -1
Help!! - java.lang.OutOfMemoryError
Help!! - java.lang.OutOfMemoryError