Currently, I have to insert over 10 billion data into my android. However, a low memory problem will cause the program to crash. The insert test in sqlite is pretty simple. Just using the for loop to create the sql insert and wrqpped "begin" and "commit" commands.
private ArrayList<String> sqlInsertCmd = new ArrayList<String>();
int QUERIES_TIMES = 10000000;
private void CreateInsertQueries()
{
Random localRandom = new Random();
int i = 0;
while (i < QUERIES_TIMES)
{
int j = localRandom.nextInt(100000);
sqlInsertCmd.add("insert into " + TABLE + " (a,b,c) values (" + i + "," +
j + ",'" + String.valueOf(j) + "')");
++i;
}
}
Then..
mDB.beginTransaction();
for (int i=0; i<this.QUERIES_TIMES; i++)
{
mDB.execSQL(sqlInsertCmd.get(i));
}
mDB.setTransactionSuccessful();
mDB.endTransaction();
Any ideas to avoid running out of memory?
Thanks to everyone, but the code above is just a simple example. In my program it is more complicated. I have to store something in a container (e.g. hashMap) and dynamically build the sql statement. Can I create 10 services and each service processes 1/10 jobs?
source
share