This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Java Interview Guide and have Anthony DePalma on-line!
See this thread for details.
The moose likes JDBC and Relational Databases 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

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "java.lang.OutOfMemoryError: Java heap space while Executing the Query" Watch "java.lang.OutOfMemoryError: Java heap space while Executing the Query" New topic

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, 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.

Rama Krishna.

Scott Selikoff
Saloon Keeper

Joined: Oct 23, 2005
Posts: 3753

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.


[OCA 8 Book] [Blog]
Marilyn de Queiroz

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

"Yesterday is history, tomorrow is a mystery, and today is a gift; that's why they call it the present." Eleanor Roosevelt
I agree. Here's the link:
subject: java.lang.OutOfMemoryError: Java heap space while Executing the Query
It's not a secret anymore!