title: Android SQLite Bulk Insert Using Transactions
body: <p>I have an insert statement and it takes my app about 25 seconds to insert ~1000 rows. I'm trying to use <code>Transactions</code> to speed up my processing time but I'm having trouble implementing it. </p>
  
  <p>Here is my method for <code>inserting</code> in my <code>DatabaseHandler</code>:</p>
  
  <pre><code>public boolean insertQuestions(String gid, String qid, String qname) {
      SQLiteDatabase db = this.getWritableDatabase();
      db.beginTransaction();
      try {
          ContentValues contentValues = new ContentValues();
          contentValues.put(KEY_GID, gid);
          contentValues.put(KEY_QID, qid);
          contentValues.put(KEY_QNAME, qname);
  
          long result = db.insert(TABLE_QUESTIONS, null, contentValues);
          db.setTransactionSuccessful();
          if (result == -1) {
              db.close();
              return false;
          } else {
              db.close();
              return true;
          }
      } finally {
          db.endTransaction(); //Error is here
      }
  }
  </code></pre>
  
  <p>I'm getting the following error when I try to run the above method:</p>
  
  <pre><code>08-28 15:50:40.961  20539-20539/? E/AndroidRuntime﹕ FATAL EXCEPTION: main
  Process: com.murrion.navigationdrawer, PID: 20539
  java.lang.IllegalStateException: attempt to re-open an already-closed object: SQLiteDatabase: /storage/emulated/0/testapp3.db
          at android.database.sqlite.SQLiteClosable.acquireReference(SQLiteClosable.java:55)
          at android.database.sqlite.SQLiteDatabase.endTransaction(SQLiteDatabase.java:522)
          at com.murrion.navigationdrawer.utils.DatabaseHandler.insertQuestions(DatabaseHandler.java:197)
  </code></pre>
  
  <p>The statement is being run in an Asynctask method in my Activity. </p>