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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T04:26:06+00:00 2026-06-04T04:26:06+00:00

I insert data into sqlite database table and when i insert first record ,

  • 0

I insert data into sqlite database table and when i insert first record , it is inserted successfully , but the second and all next records are not inserted. here is my database helper class.
i have tried the same queries in sqlite manager in firefox and they work fine. I can not get any idea why they are not working in my code.

    private static final String DATABASE_CREATE = "create table " + DATABASE_TABLE + "( " + KEY_ROWID +
        " INTEGER PRIMARY KEY AUTOINCREMENT, " + KEY_DESCRIPTION + " text, "+ KEY_WHY+" text , "+ KEY_ACCOUNTABILITY+
        " text , "+KEY_ALARM_TYPE+" text , "+KEY_ALARM_VOLUME+" text,  "+KEY_BG_IMAGE+" text, "+KEY_CATEGORY+"  text, "+KEY_DATE_TIME+  " datetime "+" , "+KEY_STATUS+" text );";
    public void addRecord(String description,String why, String accontability, String alarm_type,
            String alarm_vol, String bg_image, String category, Date goalDateTime,String status) {
        String query = "INSERT INTO " + DATABASE_TABLE + " VALUES(null,'"+ description + "', '" + why +  "', '" + accontability +"','" + alarm_type +
                "', '" + alarm_vol +  "', '" + bg_image +"','" +category+ "','" +  goalDateTime +"','"+status+"');";
        Log.v("--->", query);
        try{
        mDB.execSQL(query);



    } catch (Exception ex) {
        Log.v("database error", ex.toString());

    }
    }

here i am adding data in table

    try {
        /*
         * dbHelper = new GoalDbAdapter(this); dbHelper.open();
         * Log.v("database ","database opened"); // dbHelper. fillData();
         */
        db = new GoalDbAdapter(this);
        db.open();
        String imagePath = pref.getValue("imagePath", "");
        String goalCateg = pref.getValue("categText", "");
        String vol = pref.getValue("vol", "");
        String alarmType=  pref.getValue("ringTonePath", "");
        db.addRecord(goal_desc, goal_why, accountability, alarmType, vol, imagePath, goalCateg, goalDate,"");
         cursor = db.getTop3Goals();
        Log.v("cursor count in add act",".."+cursor.getCount());
        cursor.close();
        db.close();
    } catch (Exception ex) {
        Log.v("database error", ex.toString());

    }

Here is my code to get goals , i am unable to fetch all data , it returns only the first goal and not others. All these methods are returning only the first goal.

     public Cursor getGoals() {
    Cursor c_all = mDB.rawQuery("SELECT * FROM " + DATABASE_TABLE, null);
    int count= c_all.getCount();
    Log.v("cursor count in db all goals", c_all.getCount()+"..");
    c_all.moveToFirst();
    return c_all;
}

//SELECT * FROM table ORDER BY date DESC LIMIT 5

public Cursor getTop3Goals() {
    Cursor c = mDB.rawQuery("SELECT * FROM " + DATABASE_TABLE + " ORDER BY "+ KEY_DATE_TIME + " DESC LIMIT 3", null);
    c.moveToFirst();
    return c;
}

public Cursor getGoalsByDate() {
    Cursor c = mDB.rawQuery("SELECT * FROM " + DATABASE_TABLE + " ORDER BY "+ KEY_DATE_TIME + " DESC ", null);
    c.moveToFirst();
    return c;
}
  • 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-04T04:26:06+00:00Added an answer on June 4, 2026 at 4:26 am

    Try to change your insert method like this:

        public void addRecord(String description,String why, String accontability, String alarm_type,
                        String alarm_vol, String bg_image, String category, Date goalDateTime,String status){
    
          ContentValues initialValues = new ContentValues();
    
          initialValues.put(KEY_DESCRIPTION , description);
          initialValues.put(KEY_WHY, why);
          initialValues.put(KEY_ACCOUNTABILITY, accontability);
          initialValues.put(KEY_ALARM_TYPE, alarm_type);
    
          initialValues.put(KEY_ALARM_VOLUME, alarm_vol);
          initialValues.put(KEY_BG_IMAGE, bg_image);
          initialValues.put(KEY_CATEGORY, category);
          initialValues.put(KEY_DATE_TIME, goalDateTime);
          initialValues.put(KEY_STATUS, status);
    
          long rowId = mDB.insert(DATABASE_TABLE , null, initialValues);
    
    
    }
    

    rowId is the row id number of the new record.

    EDIT: Try the next code:

    public Cursor getGoals() {
        Cursor cursor = mDB.query(DATABASE_TABLE, null, null, null, null, null, null);
    
            if ((cursor != null) && (cursor.getCount() > 0)) {
                cursor.moveToNext();
    
                return cursor;
            }
    
        return null;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to insert data into the SQLite database using get EditText, but I
How to insert data into table in sqlite iPhone? I am trying following, but
I want to insert data into a table where I don't know the next
I am trying to insert a data into SQLite database using Python. INSERT INTO
I made iPad application in which, I want to insert record into database table,
I'm trying to insert non-latin data into sqlite database using bind variables using System.Data.SQLite.
Suppose I insert a data point into a sqlite3 database on a nightly basis.
I want to insert data into the postgresql database of OpenERP, I am able
I am trying to insert data into a table in sorted order, for later
I need to insert data into a column in the database. Which hook should

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.