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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T11:29:33+00:00 2026-06-04T11:29:33+00:00

i’m facing a problem trying to read from the internal SQLite database (Android). this

  • 0

i’m facing a problem trying to read from the internal SQLite database (Android).

this is my code of the local database:

public class LocalDatabase extends SQLiteOpenHelper{

static final String DATABASE_NAME = "database";
static final int DATABASE_VER = 2;

static final String PROFILES_TABLE_NAME = "profiles";
static final String KEY_ID = "node_id";
static final String KEY_USERID = "user_id";
static final String KEY_EMAIL = "email";
static final String KEY_FIRSTNAME = "firstname";
static final String KEY_LASTNAME = "lastname";
static final String KEY_STUDY = "study";
static final String KEY_PROFESSION = "profession";
static final String KEY_KNOWS = "knows";
static final String KEY_LOCATION = "location";
static final String KEY_STATUS = "status";
static final String KEY_POINTS = "points";
static final String KEY_GENDER = "gender";
static final String KEY_DOB = "dob";
static final String KEY_CREATED = "created";

public LocalDatabase(Context context) {
    super(context, DATABASE_NAME, null, DATABASE_VER);

}

@Override
public void onCreate(SQLiteDatabase db) {

    String CreateProfileTable = "CREATE TABLE " + PROFILES_TABLE_NAME + "(" +
                                KEY_ID + " INTEGER PRIMARY KEY," +
                                KEY_USERID + " TEXT," +
                                KEY_EMAIL + " TEXT," +
                                KEY_FIRSTNAME + " TEXT," +
                                KEY_LASTNAME + " TEXT," +
                                KEY_STUDY + " TEXT," + 
                                KEY_PROFESSION + " TEXT," +
                                KEY_KNOWS + " TEXT," +
                                KEY_LOCATION + " TEXT," +
                                KEY_STATUS + " TEXT," +
                                KEY_POINTS + " INTEGER," +
                                KEY_GENDER + " TEXT," +
                                KEY_DOB + " TEXT," +
                                KEY_CREATED + "TEXT)";

    db.execSQL(CreateProfileTable);

}

@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {

    db.execSQL("DROP TABLE IF EXISTS " + PROFILES_TABLE_NAME);

    onCreate(db);

}

public void addUserProfile(String userID, String email, String firstname, String lastname, String study, String profession, String knows,
        String location, String status, int points, String gender, String DOB, String created){

    SQLiteDatabase db = this.getWritableDatabase();

    ContentValues params = new ContentValues();

    params.put(KEY_USERID, userID);
    params.put(KEY_EMAIL, email);
    params.put(KEY_FIRSTNAME, firstname);
    params.put(KEY_LASTNAME, lastname);
    params.put(KEY_STUDY, study);
    params.put(KEY_PROFESSION, profession);
    params.put(KEY_KNOWS, knows);
    params.put(KEY_LOCATION, location);
    params.put(KEY_STATUS, status);
    params.put(KEY_POINTS, points);
    params.put(KEY_GENDER, gender);
    params.put(KEY_DOB, DOB);
    params.put(KEY_CREATED, created);

    db.insert(PROFILES_TABLE_NAME, null, params);
    db.close();


}

public ContentValues getUserProfile(){

    String query = "SELECT * FROM " + PROFILES_TABLE_NAME;
    ContentValues userProfile = new ContentValues();

    SQLiteDatabase db = this.getReadableDatabase();
    Cursor c = db.rawQuery(query, null);

    c.moveToFirst();

    if(c.getCount()>0){

        userProfile.put(KEY_USERID, c.getString(1));
        userProfile.put(KEY_EMAIL, c.getString(2));
        userProfile.put(KEY_FIRSTNAME, c.getString(3));
        userProfile.put(KEY_LASTNAME, c.getString(4));
        userProfile.put(KEY_STUDY, c.getString(5));
        userProfile.put(KEY_PROFESSION, c.getString(6));
        userProfile.put(KEY_KNOWS, c.getString(7));
        userProfile.put(KEY_LOCATION, c.getString(8));
        userProfile.put(KEY_STATUS, c.getString(9));
        userProfile.put(KEY_POINTS, c.getString(10));
        userProfile.put(KEY_GENDER, c.getString(11));
        userProfile.put(KEY_DOB, c.getString(12));
        userProfile.put(KEY_CREATED, c.getString(13));

    }

    c.close();
    db.close();

    return userProfile;

}

}

the problem is that after i insert the data into the database (using add user profile) when i’m trying to read it using (getUserProfile) all the field except user_id and email are null, i checked the params variable at addUserProfile and it’s getting the correct values

can someone explain me what i’m doing wrong?

  • 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-04T11:29:35+00:00Added an answer on June 4, 2026 at 11:29 am

    My guess is that you entered some values initially(probably only for the userid and email fields) and later didn’t clear the app’s data so the database is reconstructed again(and you continue to have those previously entered values in the database). In this case even if you entered new values you’ll build the ContentValues object(containing the results) only for the first data row from the results Cursor c(you do c.moveToFirst();). The first values are the values that only have the userid and the email and you get null for everything else.

    Also you have a typo in your sql creation string CreateProfileTable, it should be like this:

    ...KEY_CREATED + " TEXT)";
    

    Modify the CreateProfileTable string like above and then uninstall and reinstall your app.

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

Sidebar

Related Questions

For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have this code to decode numeric html entities to the UTF8 equivalent character.
I am currently running into a problem where an element is coming back from
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
Does anyone know how can I replace this 2 symbol below from the string
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
link Im having trouble converting the html entites into html characters, (&# 8217;) i

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.