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

Home Posts Topics Members FAQ

derby - java.lang.OutOf MemoryError Java heap space

7 New Member
im trying to iterate through a large database (over 5000 entries), and printing out the entries
using this code:
Expand|Select|Wrap|Line Numbers
  1. String sql = "SELECT "+column+ " ,clickurl from " + tableName;
  2. stmt = conn.prepareStatement(sql);
  3. ResultSet results=stmt.executeQuery();
  4.  
  5. while(results.next()){
  6.  
  7. String clickurl = results.getString(2);
  8. System.out.println(" Test - " + clickurl);
  9. }
  10.  
but after the 4000. entry java runs out of memory.

i dont know if i understand the system correctly, but the results are stored in the a ResultSet variable already, and iterating through it shouldn't require more memory.

i can't figure out what the problem is.
Jul 16 '08 #1
8 7443
Atli
5,058 Recognized Expert Expert
Hi.

Seeing as this is more of a Java problem than a MySQL problem, I've moved it over to the Java Forum.
Jul 16 '08 #2
Nepomuk
3,112 Recognized Expert Specialist
im trying to iterate through a large database (over 5000 entries), and printing out the entries
using this code:
Expand|Select|Wrap|Line Numbers
  1. String sql = "SELECT "+column+ " ,clickurl from " + tableName;
  2. stmt = conn.prepareStatement(sql);
  3. ResultSet results=stmt.executeQuery();
  4.  
  5. while(results.next()){
  6.  
  7. String clickurl = results.getString(2);
  8. System.out.println(" Test - " + clickurl);
  9. }
  10.  
but after the 4000. entry java runs out of memory.
It will probably help, to put
Expand|Select|Wrap|Line Numbers
  1. String clickurl = "";
before the loop and just
Expand|Select|Wrap|Line Numbers
  1. clickurl = results.getString(2);
in it. That way, you don't create a new string every time the loop is called, instead it's overwritten. Otherwise, the garbage collector would have to clean it up and it doesn't seem to be doing that in time.
i dont know if i understand the system correctly, but the results are stored in the a ResultSet variable already, and iterating through it shouldn't require more memory.
I think you're wrong with that. As I understand it, you're creating a new copy of a string every time the loop is called. It's like
Expand|Select|Wrap|Line Numbers
  1. public class CompareStrings {
  2.     public static void main(String[] args) {
  3.         StringWrapper sw = new StringWrapper();
  4.         String hi = sw.getWord();
  5.         System.out.println(hi == sw.hello);
  6.     }
  7. }
  8.  
  9. class StringWrapper {
  10.     public String hello = "Hello";
  11.     public String getWord() {return new String(hello);}
  12. }
Check it, it will return false. That's why your program runs out of memory.

Of course, you could just do this:
Expand|Select|Wrap|Line Numbers
  1. while(results.next()){
  2.  
  3. System.out.println(" Test - " + results.getString(2));
  4. }
That won't work of course, if you need the String clickurl somewhere else.

Greetings,
Nepomuk
Jul 16 '08 #3
JosAH
11,448 Recognized Expert MVP
It will probably help, to put
Expand|Select|Wrap|Line Numbers
  1. String clickurl = "";
before the loop and just
Expand|Select|Wrap|Line Numbers
  1. clickurl = results.getString(2);
in it. That way, you don't create a new string every time the loop is called, instead it's overwritten. Otherwise, the garbage collector would have to clean it up and it doesn't seem to be doing that in time.
The gc always runs when it is desparately needed; one local String doesn't
increase the consumed memory much; the gc will clean it up. I use Derby
myself and just conducted a small test: 100,000 rows without any problems
so I guess the problem is somewhere else ...

kind regards,

Jos
Jul 16 '08 #4
JosAH
11,448 Recognized Expert MVP
ps. probably your cache size is too small; e.g. set this property:

Expand|Select|Wrap|Line Numbers
  1. derby.storage.pageCacheSize    =    4M
  2.  
kind regards,

Jos
Jul 16 '08 #5
jamborta
7 New Member
hi,
thanks for the suggestions. i tried to run it without creating a string, but it still runs out of memory, although slightly later.
where can i set derby.storage.p ageCacheSize?

thanks
Jul 16 '08 #6
JosAH
11,448 Recognized Expert MVP
where can i set derby.storage.p ageCacheSize?
Put it in your System.properti es before you start Derby or use a command line
parameter -Dderby.storage. pageCacheSize=4 M

kind regards,

Jos
Jul 16 '08 #7
jamborta
7 New Member
Hi Jos,

thanks for the reply, I added these lines (-J-Dderby.storage. pageSize=8m -J-Dderby.storage. pageCacheSize=8 m) to netbeans.conf, it shows up as an argument, but doesnt seem to effect the application. it still runs out of memory, i was trying to play with the numbers, but nothing happened.

(i have 4gb memory assigned 512/512 heap/non heap memory, that should be enough i guess)
Jul 16 '08 #8
JosAH
11,448 Recognized Expert MVP
thanks for the reply, I added these lines (-J-Dderby.storage. pageSize=8m -J-Dderby.storage. pageCacheSize=8 m) to netbeans.conf, it shows up as an argument, but doesnt seem to effect the application. it still runs out of memory, i was trying to play with the numbers, but nothing happened.
I suspect the bug to be somewhere else; as I wrote, I did a little test with 100,000
rows and it ran fine, i.e. insert them and select them all. Would it be possible to
show a bit of (relevant) code? Or, alternatively, use the Runtime.freeMem ory()
method in the relevant portions of your code and see what happens; also make
sure that you close Derby's resources (result sets, statements etc.)

kind regards,

Jos
Jul 17 '08 #9

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

Similar topics

0
6811
by: Ravi Tallury | last post by:
Hi We are having issues with our application, certain portions of it stop responding while the rest of the application is fine. I am attaching the Java Core dump. If someone can let me know what the issue is. Thanks Ravi
2
1895
by: Sandy | last post by:
I am doing XSL transformation using xalan, but sometimes the input XML files are too large and that cause "java.lang.OutOfMemoryError: Java heap space" exception in xalan. Is there any way to split the xml file and do processing. I tried to use the -FLAVOR s2s assuming that it will help as xalan won't keep the xml tree in memory, but that also didn't help.
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..
6
2062
by: nickyeng | last post by:
I keep getting this error: java.lang.OutOfMemoryError: Java heap space 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.
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
8921
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9427
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9284
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...
0
9148
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...
0
8151
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4528
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
4796
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2683
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2165
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.