0

I populate a database with lots of entries, but after 7000 rows (about 600 entries), it throws java heap size limit exceeded. I tried to change the heap size in the config file of the avd from 32 to 64. I tried to put -Xmx1024 to change the heap size of all the java application (in control panel). Nothing worked so far, any suggestion? THanks in advance

up:

cv.put(KEY_NAME, "name");
cv.put(KEY_HOTNESS, "hotness");
cv.put(KEY_CALORIE, "50");
cv.put(KEY_FAT, "5");
cv.put(KEY_CARBS, "5");
cv.put(KEY_PROT, "5");
cv.put(KEY_MULTI, "1");
ourDatabase.insert(DATABASE_TABLE, null, cv);
trincot
  • 317,000
  • 35
  • 244
  • 286
Jani Bela
  • 1,660
  • 4
  • 27
  • 50
  • 3
    How do you populate the database? Can you post your code? – Xavi Gil Jun 07 '12 at 21:07
  • updated a short part from the populating, I added 600 insert of this type so far. It is working if I delete some of the, but I am afraid I need at least 600 more. – Jani Bela Jun 07 '12 at 21:11
  • I'm sorry, did you really write 600 of lines like those? If you want to change, you will go through the 600 lines again? Why don't you instead read that from a file? – m0skit0 Jun 07 '12 at 21:13
  • Yes i did. In the begining I only needed a hundred. I am not really sure how to read them from a file. If it is possible to read these from a .txt file, then could you show me how? – Jani Bela Jun 07 '12 at 21:16
  • 1
    Holy cow, you were writing these out manually? If you don't know how to extract these values from a text file, I think you might want to slow down, and do some more research before continuing on with this endeavor. – Rob Wagner Jun 07 '12 at 21:23
  • You are right, I just didnt know it was going to be such a big database. – Jani Bela Jun 07 '12 at 21:25
  • 1
    Why are you populating the database in the application? why don't you ship it pre-populated? – Xavi Gil Jun 07 '12 at 21:26
  • ^ This. There shouldn't be any massive inserts like this from the application. The database should be handled outside of your app. – Rob Wagner Jun 07 '12 at 21:29
  • Okay I will see for some tutorials on prepopulate a database from xml. – Jani Bela Jun 07 '12 at 21:30
  • 2
    You don't need that. Just create a sqlite file, put it in the raw folder, copy it to a place on the sdcard and just open it. That is all you need. – WarrenFaith Jun 07 '12 at 21:31
  • If you are going to enter everything manually, take this firefox plugin and create your database from scratch: https://addons.mozilla.org/en-US/firefox/addon/sqlite-manager/ – Xavi Gil Jun 07 '12 at 21:33
  • Thanks, I will check it later. If I use this Xavi, do I have to rewrite my existing datas? – Jani Bela Jun 07 '12 at 21:37
  • You mean the rows you already have in your database? No, you just open that file with the SQlite Manager and continue from there. – Xavi Gil Jun 07 '12 at 21:40
  • So I can open my database in sqlite manager, and continue populating it. After that what should I do with that db.file? Should I put it in the raw folder? – Jani Bela Jun 07 '12 at 21:45
  • http://stackoverflow.com/q/513084/871102 – Xavi Gil Jun 07 '12 at 21:56

1 Answers1

0

Whenever you create and add to objects in java, it will consume some of your available heap space. Instead of trying to write out and process the massive amount of queries in your code, you should process the queries in small chunks, commit those changes, and move on to more data. This way, you're only ever using a small amount of the heap space at once. There really should be no reason you have to process all of these queries at once.

As per the comments above. Unless there is some reason these massive inserts are being generated from the app, you shouldn't be doing that within the application code. Your database should be populated from outside the application.

Rob Wagner
  • 4,391
  • 15
  • 24