• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Getting Java Heap space error while adding database resultset to Hashmap

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I am getting Java Heap space error while adding database resultset to Hashmap, below is the method i am using in my application, kindly suggest how can i resolve this issue

private HashMap<String, String> loadOrganiztionMapping(Connection smDbConn) {

Statement stmnt = null;
HashMap<String,String> map = null;
try{
map = new HashMap<String,String>();
stmnt = smDbConn.createStatement();
ResultSet rs1 = stmnt.executeQuery("SELECT org_id, org_code FROM bms_organization");
while(rs1.next()){
map.put(rs1.getString("org_code"), rs1.getString("org_id"));
}
rs1.close();
}
catch(Exception e){
log.error(MobilyException.getStackTraceAsString(e));
}
finally {
if(stmnt != null){
try {
stmnt.close();
} catch (SQLException e) {
log.error(MobilyException.getStackTraceAsString(e));
}
}
}
return map;
}




javaerror.JPG
[Thumbnail for javaerror.JPG]
Error sceernshot
 
Rancher
Posts: 4801
50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When posting code can you please wrap it in code tags (there's a button on the editor page) so it retains its formatting.

How many rows are there in the table?

Does it always crash here?
Does it do that every time it enters this method, or is it only after the system has been running for some time?

What happens to the Map after it exits this method?
Is this method in a loop somewhere?
Or maybe at the end of a chain of calls that builds up a large data set?

These are the sorts of things you need to look at.

That and taking a memory dump and analysing it using something like jhat or some other analysis tool to see if you can spot what class is filling up the heap (other than String).
reply
    Bookmark Topic Watch Topic
  • New Topic