473,386 Members | 2,042 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

java.lang.OutOfMemoryError

254 100+
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 2047
r035198x
13,262 8TB
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 100+
I didn't do like this until my boss ask me to give better solution to that OutOfMemoryError....

so this is the changed code after OutOfMemoryError, 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 8TB
I didn't do like this until my boss ask me to give better solution to that OutOfMemoryError....

so this is the changed code after OutOfMemoryError, 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 100+
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 8TB
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 100+
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 OutOfMemoryError: 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
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....
1
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” & ...
1
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...
14
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...
0
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...
0
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...
1
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...
318
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 ... ...
1
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...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...

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.