File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JDBC and the fly likes java.lang.OutOfMemoryError: Java heap space while Executing the Query Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "java.lang.OutOfMemoryError: Java heap space while Executing the Query" Watch "java.lang.OutOfMemoryError: Java heap space while Executing the Query" New topic
Author

java.lang.OutOfMemoryError: Java heap space while Executing the Query

Senthil Kumar
Ranch Hand

Joined: Oct 14, 2007
Posts: 33
Hi All,
Iam trying to execute two queries which fetches lakhs of records.
** I have one Connection Object(Singleton Object).
**I have two PREPAREDSTATEMENT objects for two queries.

I get this exception when the 2ND query is getting executed.
When iam executing one query alone instead of two queries,its getting executed successfully.
So,Problem, is here.When am executing both the queries one by one, am getting this exception.

I need both the ResultSets to be used simaltaneously.so, I CANNOT
** execute the FIRST query
** Do the needfull with the FIRST ResultSet.
** execute the SECOND Query
** Do the needful with the SECOND ResultSet.


Moreover there is nothing extra in my code.Am trying to execute the Queries.Thats it.....

Can anyone Provide me a solution.?
Rama Krishna Ghanta
Ranch Hand

Joined: Nov 20, 2006
Posts: 59
Hey Senthil,

Just to understand your requirement first,you get a resultset from the first query. This resultset would be the parameters for your second query for you to execute the second one.If I am write, and from the problem description you have given, your second query is causing the problems.You can try the below method.

Instead of fetching lakhs of records at once as a single resultset,you can retrieve the data from database in chunks.for example write a "for loop" and retrieve 1000 records per every loop.

Regards,
Rama Krishna.


Ram...
Scott Selikoff
Saloon Keeper

Joined: Oct 23, 2005
Posts: 3697
    
    5

Hi Senthil,

There's no obvious reason you can't execute both queries at once, so please provide a more detailed description of your problem. Also, if you are getting OutOfMemory as your subject suggests, try increasing the JVM memory allocation using the appropriate JVM switches such as xmx and xms.

-Scott


My Blog: Down Home Country Coding with Scott Selikoff
Marilyn de Queiroz
Sheriff

Joined: Jul 22, 2000
Posts: 9043
    
  10
I had a similar problem once and it turned out to be the driver I was using.


JavaBeginnersFaq
"Yesterday is history, tomorrow is a mystery, and today is a gift; that's why they call it the present." Eleanor Roosevelt
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: java.lang.OutOfMemoryError: Java heap space while Executing the Query
 
Similar Threads
Invalid cursor state exception
Reusing Statement Object
Resultset + TYPE_FORWARD_ONLY problem
How to deal with two queries
Connection and PreparedStatement Relation...??