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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T10:12:33+00:00 2026-06-10T10:12:33+00:00

I’m having trouble with SQLiteDatabase . I’ve managed to store data into table. Unfortunately,

  • 0

I’m having trouble with SQLiteDatabase. I’ve managed to store data into table. Unfortunately, I’ve stored name inside table instead of it’s id. I need to store the id inside the table.

Please take a look at my codes and see if there’s anything wrong or anything missing from the codes.

This is my database codes
LikesDBAdapter.java

public class LikesDBAdapter extends AnniversaryDBAdapter
{
    public static final String KEY_ROWID = "likes_id";
    public static final String KEY_LIKES = "like";  
    public static final String KEY_NAME = "name_id";
    private static final String TAG = "DBAdapter";
    private static final String CREATE_TABLE_LIKES = "likes";

    //private SQLiteDatabase db;

    public LikesDBAdapter(Context ctx)
    {
        super(ctx);

    }

        public long insertLikes(String likes, String name)
        {
            ContentValues initialValues = new ContentValues();
            initialValues.put(KEY_LIKES, likes);
            initialValues.put(KEY_NAME, name);
            return db.insert(CREATE_TABLE_LIKES, null, initialValues);
        }// end insertContact()

        public boolean deleteLikes(long rowId)
        {
            return db.delete(CREATE_TABLE_LIKES, KEY_ROWID + "=" + rowId, null) > 0;
        }// end deleteContact()

        public Cursor getAllLikes()
        {
            return db.query(CREATE_TABLE_LIKES, new String[] 
                    { KEY_ROWID, KEY_LIKES, KEY_NAME }, null, null, null, null, null);
        }// end getAllContacts()

        public Cursor getLikes(long rowId) throws SQLException
        {
            Cursor mCursor = db.query(true, CREATE_TABLE_LIKES, new String[] {
                    KEY_ROWID, KEY_LIKES, KEY_NAME }, KEY_ROWID + "=" + rowId,
                    null, null, null, null, null);
            if (mCursor != null)
            {
                mCursor.moveToFirst();
            }
            return mCursor;
        }// end getContact()

}//end DBAdapter

Oh this is another database class where 5 tables are created within one DBAdapter class

public class AnniversaryDBAdapter
{

    private static final String DATABASE_NAME = "Tables";
    private static final int DATABASE_VERSION = 2;

     private static final String CREATE_TABLE_TITLE = "create table titles(title_id integer primary key autoincrement, title text not null, image text not null);";
    private static final String CREATE_TABLE_BUDDIESLIST = "create table buddiesList(name_id integer primary key autoincrement, name text not null);";
    private static final String CREATE_TABLE_LIKES = "create table likes(likes_id integer primary key autoincrement,like text not null, name text not null);";
    private static final String CREATE_TABLE_DISLIKES = "create table dislike(dlike_id integer primary key autoincrement, dislike text not null, name text not null);";
    private static final String CREATE_TABLE_EVENTS = "create table events" +
            "(event_id integer primary key autoincrement, " +
            "title text not null, location text not null, " +
            "starttime text not null, " +
            "endtime text not null, " +
            "desc text not null, " +
            "alarm text not null, " +
            "date text not null, " +
            "name_id integer not null);";

This is another code where I need to insert information into database table

btnSave = (Button) findViewById(R.id.btnSave);
        btnSave.setOnClickListener(new View.OnClickListener()
            {

                @Override
                public void onClick(View v)
                {
                    likeDB.open();
                    long like_id;

                    Spinner nameSpinner = (Spinner) findViewById(R.id.nameSpinner);
                    String NameValue = nameSpinner.getSelectedItem().toString();

                    EditText txtLikes = (EditText) findViewById(R.id.txtLikes);
                    String LikeValue = txtLikes.getText().toString();

                    like_id = likeDB.insertLikes(LikeValue, NameValue);
                    likeDB.close();

                    dlikeDB.open();
                    long dlike_id;

                    Spinner names = (Spinner) findViewById(R.id.nameSpinner);
                    String NamesValue = names.getSelectedItem().toString();

                    EditText txtDislikes = (EditText) findViewById(R.id.txtDislikes);
                    String DislikeValue = txtDislikes.getText().toString();

                    dlike_id = dlikeDB.insertDislikes(DislikeValue, NamesValue);
                    dlikeDB.close();

                    Toast.makeText(getBaseContext(), "Your information is saved successfully! :D", Toast.LENGTH_LONG).show();


                }
            });

I’ve declared the likeDB and dlikeDB above onCreate() method

LikesDBAdapter likeDB = new LikesDBAdapter(this);
DislikesDBAdapter dlikeDB = new DislikesDBAdapter(this);

UPDATE

i’ve edited the codes. I’ve removed some codes of the AnniversaryDBAdapter class in the post.

  • 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-10T10:12:34+00:00Added an answer on June 10, 2026 at 10:12 am

    Why are you surprised? You are inserting name in the database in your insertLikes function

        public long insertLikes(String likes, String name)
        {
            ContentValues initialValues = new ContentValues();
            initialValues.put(KEY_LIKES, likes);
            ***initialValues.put(KEY_NAME, name);***
            return db.insert(CREATE_TABLE_LIKES, null, initialValues);
        }// end insertContact()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm having trouble keeping the paragraph square between the quote marks. In firefox the
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I have a French site that I want to parse, but am running into
In my XML file chapters tag has more chapter tag.i need to display chapters
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I am currently running into a problem where an element is coming back from
I need a function that will clean a strings' special characters. I do NOT

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.