Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6930681
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T11:28:45+00:00 2026-05-27T11:28:45+00:00

I have an embedded database with my app. it’s in the asset folder. The

  • 0

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:

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();
            }
          });

and the relevant method in my SQliteOpenHelper class is:

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);
        }

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.

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:

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();

            }
        });

previously, i was using this:

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();

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T11:28:46+00:00Added an answer on May 27, 2026 at 11:28 am

    There’s nothing wrong with your code, it should insert the passed value in the column.

    Try to make sure you have a value by adding some kind of debug alert, like a Toast:

    String editmacs=editmac.getText().toString();
    Toast.makeTest(getApplicationContext(), "Value to insert = " + editmacs, Toast.LENGTH_SHORT).show();
    db.insertrow(editmacs); 
    

    And let me know if you get the value you expect. If no (which is my guess), then that’s probably because you read the text value from the wrong TextView.

    Are you sure editmac is correctly initialized from the right view?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Java app that has an embedded Derby database (no hibernate though).
I have an embedded database in an asp.net mvc project. If I try to
I have a .Net 4.0 WPF application that requires an embedded database. MS Access
I have a desktop .NET WPF application witch uses an embedded database (SQLite). Where
I seem to have an issue with connecting to an embedded FireBird database from
I'm new to designing OO systems. I have a simple Flash Cards app where
I have a WPF 4 app with a ComboBox embedded in a DataGrid. The
I have to create a table (H2 embedded database) using fields from other tables.
Is it possible to have an embedded database as a file shared on a
For my application I need an embedded database. I don't have a lot of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.