Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid, SQLite: Inserting data in while clause is very slow
    primarykey
    data
    text
    <p><em><strong>SOLUTION AT THE BOTTOM OF THE QUESTION</em></strong></p> <p>I have a FTP Server with more than 3'000 pictures on it and I save the picture names to an ArrayList. After this I'd like to save them from arraylist to database and that is taking very very very very much time! See:</p> <p>With</p> <pre><code> FTPFile[] files = ftpClient.listFiles(); for (FTPFile file : files) { imageNames.add(file.getName()); } </code></pre> <p>I get a list of all those files and save them into the ArrayList imageNames. This is very fast and don't take more than 1 - maximum 2 seconds.</p> <p>Now I like to write this array backwards to my sqlite database. When I do this it takes extremly long to be finished! I waited more than 2 minutes for it...</p> <pre><code> int i = imageNames.size() - 1; int q = 0; while(i &gt;= 0){ String insert_arraylist = "INSERT INTO ARRAYLIST (STRING) VALUES ('"+imageNames.get(q)+"')"; db.execSQL(insert_arraylist); i--; q++; } </code></pre> <p>So how can I speed up this inserting??</p> <p>Thanks in advance!</p> <p><strong>SOLUTION:</strong> (From more than 2 minutes to less than 3 seconds ;))</p> <pre><code> FTPFile[] files = ftpClient.listFiles(); insert_arraylist = ""; ContentValues con = new ContentValues(); for (FTPFile file : files) { imageUrls.add("http://192.168.99.104/GetThePicture/thumbs/"+file.getName()); } int i = imageUrls.size() - 1; int q = 0; db.beginTransaction(); try{ while(i &gt;= 0){ String insert_arraylist = "INSERT INTO ARRAYLIST (STRING) VALUES ('"+imageUrls.get(q)+"')"; db.execSQL(insert_arraylist); i--; q++; } db.setTransactionSuccessful(); } catch(Exception e){ } finally { db.endTransaction(); } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload