• 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 all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
  • Tim Cooke
  • Knute Snortum
  • Bear Bibeault
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Ganesh Patekar
  • Frits Walraven
  • Carey Brown
  • Tim Holloway

java.lang.OutOfMemoryError: Java heap space

Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,
I have wriiten a query which will fetch records more than 2 lakhs.
and i have written the code as
PreparedStatement pstmt = connection.prepareStatement("select * from BIG_TABLE where col1=?");

When i execute this code am getting
java.lang.OutOfMemoryError: Java heap space
I get this exception when the code executes executeQuery().

Can anyone provide me a solution ?
Thanks in advance
Ranch Hand
Posts: 341
Firefox Browser Spring Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Out of memory simply means the memory consumption by the application exceeds the total memory available for JVM.

The problem can occur if your code is sloppy. Precisely if you have a memory leak. So the buzzword is optimize and stabilize your code.

Other than that it says that your Java application needs a lot of memory (more than 128 MB of default). In this case the Java heap size can be increased using the runtime parameters:

java -Xms<initial heap size> -Xmx<maximum heap size>

The default values are java -Xms32m -Xmx128m

Also, you may refer this post with similar issues.

Hope that helps.
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!