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

  • SEARCH
  • Home
  • 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 6943473
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T13:09:38+00:00 2026-05-27T13:09:38+00:00

I am new to SQL.I have a database of mac-addresses which i created using

  • 0

I am new to SQL.I have a database of mac-addresses which i created using Sqliteman browser. It is a simple database with just one table named “access_points”. The database named macad.db is in my assets folder.I have an application to insert new mac-addresses to the table access_points from an edittextview. My DB Adapter has following initializations:

public static String DATABASE_NAME="macad.db";
public static String DATABASE_PATH= "/data/data/com.example.myproject/databases/";
public static String LOCAL_DATABASE_NAME="macad.db";

what should be the value for my table’s(access_points) initialization. Kindly replace the question marks with your answer.

public static String DATABASE_TABLE= ????;

in addition my insertmac method in DB Adapter is given below. How would i refer to my table “access_points” of macad.db which is stored in assets folder? please replace the question marks with your answer in db.insert() statement provided below.

public long insertmac(String mac) 
    {
        ContentValues macValue = new ContentValues();
        macValue.put("macaddress1", macaddress1);
        return db.insert(????, null, macValue);
    }

Also is there any way to ensure that, if a mac-address already exists in the access_points table it is not put again in the table?? Thanks in advance for any solution.my DBAdapter class is below:

public class DbAdapternew {
    private static final String TAG = DbAdapter.class.getName();
    //private DatabaseHelper mDbHelper;
    public static SQLiteDatabase myDb;
    public static String DATABASE_NAME="macad.db";
    public static String DATABASE_TABLE="access_points";
    public static String DATABASE_PATH= "/data/data/com.example.myproject/databases/";
    public static String LOCAL_DATABASE_NAME="macad.db";
    private static final int DATABASE_VERSION = 2;
    private static Context myContext;
    public static final String KEY_MAC = "mac_add"; // column 1
    public static final String KEY_floor = "floor_id";  // column 2
    public static final String KEY_build= "building_id"; //column 3
    public static final String KEY_zone = "zone_id";      // column 4 
    private DatabaseHelper DBHelper;
    private static class DatabaseHelper extends SQLiteOpenHelper {



        Context helperContext;

        DatabaseHelper(Context context) {
            super(context, DATABASE_NAME, null, DATABASE_VERSION);
            helperContext = context;
        }


        @Override
        public void onCreate(SQLiteDatabase db) {
        }

        @Override
        public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
            Log.w(TAG, "Upgrading database!!!!!");
            onCreate(db);
        }

        public void createDataBase() throws IOException {
            Log.i(TAG,"DB NAME : "+DATABASE_NAME);
            Log.i(TAG,"DB PATH : "+DATABASE_PATH);
            Log.i(TAG,"LOCAL DB NAME : "+LOCAL_DATABASE_NAME);


            boolean dbExist = checkDataBase();
            if (dbExist) {
            } else {
                this.getReadableDatabase();
                try {
                    copyDataBase();
                } catch (IOException e) {
                    //throw new Error("Error copying database");
                }
            }
        }

        public SQLiteDatabase getDatabase() {
            String myPath = DATABASE_PATH + DATABASE_NAME;
            return SQLiteDatabase.openDatabase(myPath, null,
                    SQLiteDatabase.OPEN_READONLY);
        }

        private boolean checkDataBase() {
            SQLiteDatabase checkDB = null;
            try {
                String myPath = DATABASE_PATH + DATABASE_NAME;
                checkDB = SQLiteDatabase.openDatabase(myPath, null,
                        SQLiteDatabase.OPEN_READONLY);
            } catch (SQLiteException e) {
            }
            if (checkDB != null) {
                checkDB.close();
            }
            return checkDB != null ? true : false;
        }

        private void copyDataBase() throws IOException {

            Log.i(TAG,"LOCAL DB NAME : "+LOCAL_DATABASE_NAME);
            // Open your local db as the input stream
            InputStream myInput = myContext.getAssets().open(LOCAL_DATABASE_NAME);

            // Path to the just created empty db
            String outFileName = DATABASE_PATH + DATABASE_NAME;

            // Open the empty db as the output stream
            OutputStream myOutput = new FileOutputStream(outFileName);

            // transfer bytes from the inputfile to the outputfile
            byte[] buffer = new byte[1024];
            int length;
            while ((length = myInput.read(buffer)) > 0) {
                myOutput.write(buffer, 0, length);
            }

            // Close the streams
            myOutput.flush();
            myOutput.close();
            myInput.close();
        }

        public void openDataBase() throws SQLException {
            // Open the database
            String myPath = DATABASE_PATH + DATABASE_NAME;
            myDb = SQLiteDatabase.openDatabase(myPath, null,
                    SQLiteDatabase.OPEN_READWRITE);
        }

        @Override
        public synchronized void close() {

            if (myDb != null)
                myDb.close();

            super.close();

        }
    }


    public DbAdapternew(Context ctx) {
        this.myContext = ctx;
        DBHelper = new DatabaseHelper(ctx);
    }

    public DbAdapternew open() throws SQLException {
        myDb = DBHelper.getWritableDatabase();

        return this;

    }

    public void close() {
        DBHelper.close();
    }

    public Cursor fetchAllData(String table) {

        try {
            myDb.rawQuery("SELECT * FROM " + table, null);
            Log.i(TAG, "Row Collected");
        } catch (SQLiteException e) {
            myDb.execSQL("CREATE TABLE IF NOT EXISTS " + table
                    + " (mac_add VARCHAR)");
            Log.i(TAG, "TABLE Not Found");
        }
        return myDb.rawQuery("SELECT * FROM " + table, null);
    }

    public Cursor fetchData(String sqlQuery) {

        try {
            myDb.rawQuery(sqlQuery, null);
            Log.i(TAG, "Query Executed");
        } catch (SQLiteException e) {
            Log.i(TAG, e.toString());
        }
        return myDb.rawQuery(sqlQuery, null);
    }

    public void executeQuery(String sql) {
        myDb.execSQL(sql);
    }
     public long insertrow(String editmac) 
        {
            ContentValues initialValues = new ContentValues();
            initialValues.put(KEY_MAC, editmac.toString());  //for column 1 in macad.db
            initialValues.put(KEY_floor, "uf");            //for column 2 
            initialValues.put(KEY_build, "ub");            //for column 3
            initialValues.put(KEY_zone, "uz");             //for column 4
            return myDb.insert(DATABASE_TABLE, null, initialValues);
        }

}

In my activity there is an update button pressing which should result in putting the typed mac-address in edittextview into the macad.db. the code for this is:

updzonedb.setOnClickListener(new View.OnClickListener() {
            public void onClick(View view) {
                db.open();
                try
                {

                  db.insertrow(editmac.getText().toString());   


                 }
                catch (Exception ex)
                {

                  }
                db.close();
            }
          });
  • 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-27T13:09:39+00:00Added an answer on May 27, 2026 at 1:09 pm

    Have you copied your database .db file from asset to data/data/<package_name>databases directory?

    If yes then go ahead use the same table name which is in your database when you created using SQLIte Manager.

    If NO then go through this SO Question How to ship an Android application with a database?

    public static String DATABASE_TABLE= "access_points";
    

    and

    public long insertmac(String mac) 
        {
            ContentValues macValue = new ContentValues();
            macValue.put("macaddress1", macaddress1);
            return db.insert(DATABASE_TABLE, null, macValue);
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm pretty new to SQL. I have a database with records based on road/milepoints.
I am new to LINQ to SQL, but have done a lot of database
Hi I'm very new to sql but have been passed a job in which
I am totally new to SQL . I have a simple select query similar
I am pretty much new to using SQL Server 2000. I have been using
I have the following transaction: SQL inserts a 1 new record into a table
I have a SQL database that I'm using LINQ to connect to (LINQ To
I'm new to asp, so be patient :p I have an sql database, with
We have moved a database from SQL 2000 to a new SQL 2005 that
I am creating a new SQL Server 2008 database. I have two two tables

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.