title: Passing an array of data into a SQLite Database in android
body: <p>I am using an array to send data to my SQLite Database.<br>
  The array contains all the selected values.</p>
  
  <pre><code> private void addContacts(String[] selectedItems) {
  
      manager.Insert_phone_contact(selectedItems);
      Intent i = new Intent(this, MainActivity.class);    
      startActivity(i);
  }
  </code></pre>
  
  <p>My SQLite databse code to insert the above mentioned "selectedItems" array in contentvalues is as follows:</p>
  
  <pre><code>public void Insert_phone_contact(String [] contact){
      try{
  
          SQLiteDatabase DB = this.getWritableDatabase();
          for(int i=0;i&lt;contact.length;i++){
              ContentValues cv = new ContentValues();
              cv.put(CONTACT_NAME, contact[i]);
              DB.insert(TABLE_CONTACTS, null, cv);
              DB.close();
          }
          }
      catch(Exception ex){
          Log.e("Error in phone contact insertion", ex.toString());
      }
  </code></pre>
  
  <p>Only the first array item is stored in <code>ContentValues</code> cv, not all the array elements.<br>
  What's wrong in this code?<br>
  How can I insert all the array items in the "TABLE_CONTACTS" table?<br>
  Any help will be appreciated.</p>