title: sqlite insert on button click
body: <p>I have an embedded database with my app. it's in the asset folder. The user should be able to add new rows to the database on button click. I have the following code for that:</p>
  
  <pre><code>insertrow.setOnClickListener(new View.OnClickListener() {
              public void onClick(View view) {
                  db.open();
                  try
                  {
                      String editmacs=editmac.getText().toString();
                      db.insertrow(editmacs); 
                  //  Context context = getApplicationContext();
  
                  }
                  catch (Exception ex)
                  {
                    Toast.makeText(getApplicationContext(), "cannot update", Toast.LENGTH_LONG).show();
                    }
                  db.close();
              }
            });
  </code></pre>
  
  <p>and the relevant method in my SQliteOpenHelper class is:</p>
  
  <pre><code>public static SQLiteDatabase myDb;
  public static String DATABASE_TABLE="access_points";
  public static final String KEY_column1 = "col1";
  public static final String KEY_column2 = "col2";
  public static final String KEY_column3= "col3";
  public static final String KEY_column4 = "col4";
  
  public long insertrow(String editmacs) 
          {
              ContentValues initialValues = new ContentValues();
              initialValues.put(KEY_column1, editmacs);
              initialValues.put(KEY_column2, "uf");
              initialValues.put(KEY_column3, "ub");
              initialValues.put(KEY_column4, "uz");
              return myDb.insert(DATABASE_TABLE, null, initialValues);
          }
  </code></pre>
  
  <p>The problem is with button click the editmacs (KEY_column1) is not inserted into the database. But the other values(FOR EXAMPLE "uz") are inserted(i tested the inserted values with sql query). During insertion using buttonpress i dont get any exception. Can anyone tell why editmacs value from edittext is not inserted? Thanks in advance.    </p>
  
  <p>Ok i got the solution from Guillaume's comments (see below). The queries related to insert are ok. The problem is elsewhere. Look at the following code:</p>
  
  <pre><code>buttonuserentry.setOnClickListener(new View.OnClickListener() {
              public void onClick(View view) {
                  db.open();
                  try
                  {
                      String mac = "";
                      mac = db.getuserentry();
                      Context context = getApplicationContext();
                      String text = mac;
                      int duration = Toast.LENGTH_LONG;
  
                      Toast toast = Toast.makeText(context, text, duration);
                      toast.show();
                  }
                  catch (Exception ex)
                  {
                      Context context = getApplicationContext();
                      CharSequence text = ex.toString();
                      int duration = Toast.LENGTH_LONG;
  
                      Toast toast = Toast.makeText(context, text, duration);
                      toast.show();
                  }
                  db.close();
  
              }
          });
  </code></pre>
  
  <p>previously, i was using this:             </p>
  
  <pre><code>CharSequence mac = "";    
  mac = db.getuserentry();
  Context context = getApplicationContext();
  String text = mac;
  int duration = Toast.LENGTH_LONG;
  Toast toast = Toast.makeText(context, text, duration);
  toast.show();
  </code></pre>
  
  <p>Because i was using CharSequence, it was showing the last inserted mac address from the original database. The original embedded database declared this column as Text(so that means Text= CharSequence in Sqliteman). My expected mac address is the last typed mac address by the user. This mac address from editmac view is converted to String. So, one must retrieve it as String, not as CharSequence. Thanks again to Guillaume's help in directing me to the solution. </p>