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 8502067
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T01:22:59+00:00 2026-06-11T01:22:59+00:00

I am using SQLite database to store few Strings. I am using this code

  • 0

I am using SQLite database to store few Strings. I am using this code to add those strings when i launch the application for the 1st time.

DatabaseHandler db = new DatabaseHandler(this);
db.addProducts(//lot of strings appended to make a single String);
db.close();

DatabaseHandler is:

public class DatabaseHandler extends SQLiteOpenHelper {

    private static final int DATABASE_VERSION = 1;
    public static final String DATABASE_NAME = "my_db";
    private static final String TABLE_NAME = "products";
    private static final String KEY_NAME = "pname";

    public DatabaseHandler(Context context) {
        super(context, DATABASE_NAME, null, DATABASE_VERSION);
    }

    @Override
    public void onCreate(SQLiteDatabase db) {

        String CREATE_PRODUCTS_TABLE = "CREATE TABLE " + TABLE_NAME + "("
                + KEY_NAME + " TEXT" + ")";
        db.execSQL(CREATE_PRODUCTS_TABLE);
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        db.execSQL("DROP TABLE IF EXISTS " + TABLE_NAME);
        onCreate(db);
    }

    public void addProducts(String product_name) {

        SQLiteDatabase db = this.getWritableDatabase();
        ContentValues values = new ContentValues();
        values.put(KEY_NAME, product_name); // Product Name
        db.insert(TABLE_NAME, null, values);
        db.close();
    }

    public String getProducts() {

        SQLiteDatabase db = this.getReadableDatabase();
        String selectQuery = "SELECT  * FROM " + TABLE_NAME;
        Cursor cursor = db.rawQuery(selectQuery, null);
        String s = "default";
        if (cursor.moveToFirst()) {
            int n = cursor.getCount();
            s = cursor.getString(0);
        }
        cursor.close();
        return s;
    }
}

The problem is if i am not checking whether the table products exists, i will call the db.addProducts(""); every time the application is lauched. And the cursor count increases by 1 everytime and eventually says need to extend db something like that. How can i check if the Table is already present??

I can only find this: How to check if database exists :

public static boolean checkDataBase(String DB_FULL_PATH) {
    SQLiteDatabase checkDB = null;
    try {
        checkDB = SQLiteDatabase.openDatabase(DB_FULL_PATH, null,
                SQLiteDatabase.OPEN_READONLY);
        checkDB.close();
    } catch (SQLiteException e) {
        // database doesn't exist yet.
    }
    return checkDB != null ? true : false;
}

Here i am stuck with the path. How can i get the path of the Database?

Moreover it would be useful if i check whether a Table exists rather than the Database.

Thank You

  • 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-06-11T01:23:01+00:00Added an answer on June 11, 2026 at 1:23 am

    I think this would be helpfull for the PATH-Question. Found in the tutorial from: http://www.vogella.com/articles/AndroidSQLite/article.html#sqliteoverview
    ” Access to an SQLite database involves accessing the filesystem. This can be slow. Therefore it is recommended to perform database operations asynchronously, for example inside the AsyncTask class.

    If your application creates a database, this database is by default saved in the directory DATA/data/APP_NAME/databases/FILENAME.

    The parts of the above directory are constructed based on the following rules. DATA is the path which the Environment.getDataDirectory() method returns. APP_NAME is your application name. FILENAME is the name you specify in your application code for the database. “

    So, for one db exists one file in die filesystem. That is /data/data/package.name/databases.
    package.name is the the packagename of your application. databases is the name of your db.

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

Sidebar

Related Questions

Hi In my application I am using SQLITE database, I want to add multiple
I'm developing an Android application and i'm using a Sqlite database to store some
I am using the SQLite database to store data in my application. Can the
I am using sqlite database. I used the following code to store three values
I am using an sqlite database to store log data. My table has a
I have been working with iPhone application in which i am using sqlite database.
I am using the Sqlite Database in my Application, I have already upload my
I am using a SQLite database to store values from a data logger. The
I am using SQLITE database and I store the date as a String. Now
I'm using a SQLite database to store information on players and their teams using

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.