473,729 Members | 2,331 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

java.lang.OutOf MemoryError

254 Contributor
I keep getting this error:
Expand|Select|Wrap|Line Numbers
  1. java.lang.OutOfMemoryError: Java heap space
  2.  
what possible reason that cause this error ?

My boss dont want increase java memory, so i had to change my code.

My code have sql statement and my database table has 60000 rows(record) and keep increasing.

I call this to retrieve data from table:
Expand|Select|Wrap|Line Numbers
  1. double total = Billing.getTotalAmount(String str);
  2.  
so in that Billing class has a method called getTotalAmount which doing the sql statement and sum the amount for certain column amount and return it.

Still, it can't runs and give same error.

Any idea ?

thanks in advance
from
Nick
Sep 18 '07 #1
6 2061
r035198x
13,262 MVP
I keep getting this error:
Expand|Select|Wrap|Line Numbers
  1. java.lang.OutOfMemoryError: Java heap space
  2.  
what possible reason that cause this error ?

My boss dont want increase java memory, so i had to change my code.

My code have sql statement and my database table has 60000 rows(record) and keep increasing.

I call this to retrieve data from table:
Expand|Select|Wrap|Line Numbers
  1. double total = Billing.getTotalAmount(String str);
  2.  
so in that Billing class has a method called getTotalAmount which doing the sql statement and sum the amount for certain column amount and return it.

Still, it can't runs and give same error.

Any idea ?

thanks in advance
from
Nick
You may need to post the getTotalAmount method ...
Sep 18 '07 #2
nickyeng
254 Contributor
I didn't do like this until my boss ask me to give better solution to that OutOfMemoryErro r....

so this is the changed code after OutOfMemoryErro r, but still, it gets the same Error.

this is the code :

Expand|Select|Wrap|Line Numbers
  1. double total = 0;
  2. Connection conn = DbConnectionManager.getConnection();
  3.         try{
  4.             PreparedStatement st = conn.prepareStatement("select sum(amount) from billing where no like \'"+no+"%\' and  billing_date like \""+String.valueOf(year)+"%\" ");
  5.             ResultSet rs = st.executeQuery();
  6.             while(rs.next())
  7.                 total = rs.getDouble(1);
  8.  
  9.             rs.close();
  10.             st.close();
  11.  
  12.                         return total;
  13.         }finally
  14.         {
  15.             DbConnectionManager.release(conn);
  16.         }
  17.  
  18.  
  19.  
Sep 18 '07 #3
r035198x
13,262 MVP
I didn't do like this until my boss ask me to give better solution to that OutOfMemoryErro r....

so this is the changed code after OutOfMemoryErro r, but still, it gets the same Error.

this is the code :

Expand|Select|Wrap|Line Numbers
  1. double total = 0;
  2. Connection conn = DbConnectionManager.getConnection();
  3.         try{
  4.             PreparedStatement st = conn.prepareStatement("select sum(amount) from billing where no like \'"+no+"%\' and  billing_date like \""+String.valueOf(year)+"%\" ");
  5.             ResultSet rs = st.executeQuery();
  6.             while(rs.next())
  7.                 total = rs.getDouble(1);
  8.  
  9.             rs.close();
  10.             st.close();
  11.  
  12.                         return total;
  13.         }finally
  14.         {
  15.             DbConnectionManager.release(conn);
  16.         }
  17.  
  18.  
  19.  
And approximately how many records do you have in that table?
You don't need a while there you can replace that with an if as in
Expand|Select|Wrap|Line Numbers
  1. if(rs.next()) {
  2.       total = rs.getDouble(1); 
  3. }
  4.  
Sep 18 '07 #4
nickyeng
254 Contributor
And approximately how many records do you have in that table?
You don't need a while there you can replace that with an if as in
Expand|Select|Wrap|Line Numbers
  1. if(rs.next()) {
  2.       total = rs.getDouble(1); 
  3. }
  4.  
60000 records and keep increasing.
Sep 18 '07 #5
r035198x
13,262 MVP
60000 records and keep increasing.
You did put printlns before and after the sql is executed to make sure that it's the querying that taking up all the memory?
Perhaps you should increase the heap size then (See the JVM thread in this forum).
Isn't there a way of optimizing your query?
Sep 18 '07 #6
nickyeng
254 Contributor
You did put printlns before and after the sql is executed to make sure that it's the querying that taking up all the memory?
Perhaps you should increase the heap size then (See the JVM thread in this forum).
Isn't there a way of optimizing your query?

i was using the for loop in my JSP to loops Billing object that returns by a method which is simple query like :
Expand|Select|Wrap|Line Numbers
  1. select count(*) from table1 where name = 'nick' and year = 'year';
  2.  
that Billing object consist of all(60000+) records, and then loops it and total up the amount.

This BOLD part was the original code i've done.

So i package up project as war file, and run in my server, it gives me OutOfMemoryErro r: java heap space.

So, boss ask me to change my code so that let it be more simpler and take lesser memory because he dont want increase the java memory(jvm thing).

In the end, i came up with the code i posted in the 1st post.

now, i still getting the same error.
haiz.
Sep 18 '07 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

1
3177
by: novel | last post by:
Hi, i wrote a java program, that create a rdf file parsing a file tree. On the last step the shockwaves and gifs are checked and the byte sizes are written in the rdf file as nodes. The 1. Problem: A java.lang.OutOfMemoryError is throwm. Sometimes on the 45 shockwave, sometimes on the 53 shockwave...
1
5449
by: Marwa5 | last post by:
I’m a service desk 4.5 administrator & I have a lot of java errors on our servers & SD application so kindly check below errors & waiting your help: “Java.lang.OutOfMemoryError” & “java.lang.NullPointerException”
1
2629
by: sunilkumar.r80 | last post by:
Hi I have a problem in reading a .xls file using java. I am using jakarta POI ApI for that it work fine for a 9000 rows contians 25 colums. But i need to read more than 25000 rows (in a single sheet) It shows the message " java.lang.OutOfMemoryError: Java heap space" so can any one help me in this time Thanks
14
5686
by: mlw | last post by:
Do not take anything about this, it is not a flame or troll, while I'm not new to Java I favor C++. However, I may need to use it in a contract position, and am concerned that the restrictions it places on application code. Take, for instance, this C++ construct: class foo { char *m_name;
0
2557
by: subashinicse | last post by:
hi everybody, am working with J2EE &hibernate... while i run my application,am sending an object(filetype of size more than 8MB) from jboss to securityserver,where am getting ERROR as java.lang.outofMemoryerror: java heap space,i tried by changing the java heap size in jboss. but still am getting the error. can anybody help me out!!! its urgent!!!! thank you..
0
1400
by: subashinicse | last post by:
hi everybody, am working with J2EE &hibernate... while i run my application,am sending an object(filetype of size more than 8MB) from jboss to securityserver,where am getting ERROR as java.lang.outofMemoryerror: java heap space,i tried by changing the java heap size in jboss. but still am getting the error. can anybody help me out!!! its urgent!!!! thank you..
1
1133
by: KritiGuleria | last post by:
Hi i am getting an error java.lang.OutOfMemoryError while running a few java files. i have already increased JVM heap memory (Xmx=512 and Xms=512 from 256). but this didnot fix my problem. the RAM of my system is 1GB. Please suggest me what should be done in order to solve this issue
318
11045
by: King Raz | last post by:
The shootout site has benchmarks comparing different languages. It includes C# Mono vs Java but not C# .NET vs Java. So I went through all the benchmark on the site ... http://kingrazi.blogspot.com/2008/05/shootout-c-net-vs-java-benchmarks.html Just to keep the post on topic for my friends at comp.lang.c++, how do I play default windows sounds with C++?
1
7125
by: HxRLxY | last post by:
I have a program that shows a thumbnail of an image. If the user clicks on the thumbnail a new JFrame is opened that shows the full size image. If the image is larger than the screen, it gets scaled to the the size of the screen. Functionally, the program works well. However, when testing I found that after clicking the thumbnails of several images (and subsequently closing their viewing frames), I get an java.lang.OutOfMemoryError: Java...
0
8761
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9281
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9200
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9142
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6722
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6022
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4525
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4795
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3238
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.