title: How to insert data into a table in android using sqlite?
body: <p>I am trying to insert a value into a SQLite database. I have two tables in the database but the value is not getting inserted into my second table i.e mynum table. I have used the same codes for insertion into the first table but it doesn't work for the second table. How can i fix this?
  Here's my code</p>
  
  <p>Databasehandler.java</p>
  
  <pre><code>public class Databasehandler extends SQLiteOpenHelper{
      private static final String LOGCAT = null;
  
      public Databasehandler(Context applicationcontext) {
          super(applicationcontext,"androidsqlite.db", null, 4);
          // TODO Auto-generated constructor stub
          Log.d(LOGCAT,"Database Created");
      }
  
      @Override
      public void onCreate(SQLiteDatabase db) {
          // TODO Auto-generated method stub
          String query,query1;    
          query = "CREATE TABLE userlogin ( phoneId INTEGER PRIMARY  KEY,
                                     username TEXT,userid INTEGER,contacts INTEGER)";
  
          query1 = "CREATE TABLE mynum ( Id INTEGER PRIMARY KEY,num INTEGER)";
          db.execSQL(query1);
          db.execSQL(query);
          //db.execSQL(query1);
      }
  
      @Override
      public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
          // TODO Auto-generated method stub
          String query,query1;
          query  = "DROP TABLE IF EXISTS userlogin";
          query1 = "DROP TABLE IF EXISTS mynum";
          db.execSQL(query);
          db.execSQL(query1);
          onCreate(db);
      }
  
      public void communityfragment(HashMap&lt;String, String&gt; queryvalues) {
          // TODO Auto-generated method stub
          SQLiteDatabase database = this.getWritableDatabase();
          ContentValues values    = new ContentValues();
          values.put("num",queryvalues.get("number"));
          database.insert("mynum", null, values);
          database.close();
      }
  </code></pre>
  
  <p>And here's my CommunityFragment.java class</p>
  
  <pre><code>public class CommunityFragment extends Fragment {
      HashMap&lt;String, String&gt; d=new HashMap&lt;String, String&gt;();
      d.put("number",f);
      //nameValuePairs.add(new BasicNameValuePair("email","abc"));
      Toast.makeText(getActivity(),"incommunityfragment"+d,Toast.LENGTH_LONG).show();
      db.communityfragment(d);
  
  }
  </code></pre>