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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T14:53:46+00:00 2026-06-09T14:53:46+00:00

I have a insertion method which cheks first if the row is available or

  • 0

I have a insertion method which cheks first if the row is available or not, if not then it tries to create new or if available then it updates that, but this method giving me the exception in the else part, here is my method

public long SetSettings(String whichCol, String value) {
        // TODO Auto-generated method stub
        preferences = ourcontext.getSharedPreferences(filenames, 0);
        String[] colum = new String[] { KEY_CAR };
        Cursor c = ourDB.query(DBhelper.DATABASE_SETTINGSTABLE, colum, KEY_CAR
                + "=" + "'" + preferences.getString("selectedcar", "") + "'",
                null, null, null, null);
        ContentValues cvedit = new ContentValues();
        cvedit.put(KEY_CAR, preferences.getString("selectedcar", ""));
        cvedit.put(whichCol, value);
        if (c.getCount() > 0) {

            return ourDB.update(
                    DBhelper.DATABASE_SETTINGSTABLE,
                    cvedit,
                    KEY_CAR + "=" + "'"
                            + preferences.getString("selectedcar", ""), null);

        } else {

            return ourDB.insert(DBhelper.DATABASE_SETTINGSTABLE, null, cvedit);

        }
    }

and this is how I created my database:

public static final String KEY_ID = "_id";
public static final String KEY_CAR = "car";   
public static final String KEY_SET_DISENTRY_MODE = "ditance_entry_mode";
        public static final String KEY_SET_DISUNIT = "distance_unit";
        public static final String KEY_SET_PETROLUNIT = "petrol_unit";
        public static final String KEY_SET_CONDISPLAY = "consumption_display";
        public static final String KEY_SET_DATEFORMAT = "date_format";
        public static final String KEY_SET_CURRENCY = "currency";
        public static final String KEY_SET_STOREFILLLOC = "store_fillloc";
        public static final String KEY_SET_GPSPIN = "gps_pin";
        public static final String KEY_SET_KEYCLICK = "keyboard_click";
        public static final String KEY_SET_KEYVIBRATE = "keyboard_vibrate";
        public static final String KEY_SET_BACKUP = "backup";

@Override
    public void onCreate(SQLiteDatabase db) {
        // TODO Auto-generated method stub

        db.execSQL("CREATE TABLE " + DATABASE_SETTINGSTABLE + " (" + KEY_ID
                + " INTEGER PRIMARY KEY AUTOINCREMENT, " + KEY_CAR
                + " TEXT NOT NULL, " + KEY_SET_DISENTRY_MODE + " TEXT, "
                + KEY_SET_DISUNIT + " TEXT, " + KEY_SET_PETROLUNIT + " TEXT, "
                + KEY_SET_CONDISPLAY + " TEXT, " + KEY_SET_DATEFORMAT
                + " TEXT, " + KEY_SET_CURRENCY + " TEXT, "
                + KEY_SET_STOREFILLLOC + " TEXT, " + KEY_SET_GPSPIN + " TEXT, "
                + KEY_SET_KEYCLICK + " TEXT, " + KEY_SET_KEYVIBRATE + " TEXT, "
                + KEY_SET_BACKUP + " TEXT NOT NULL);");

    }

I cant figure out where is my problem, any help?

  • 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-09T14:53:47+00:00Added an answer on June 9, 2026 at 2:53 pm

    you have a constraint KEY_SET_BACKUP TEXT NOT NULL but when updating you are passing null as this value, so add below line too to the contentvalues

    cvedit.put(KEY_SET_BACKUP,"");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to have a field which is updated on every change(insertion, modification),
I'm new to CodeIgniter and have come into an issue with the insertion of
I have an object Producer which internally starts a thread that will listen for
On a current project which I'm currently working, i have a symfony task that
I have written this method which given a number and a list will return
I have several strings which may or may not be empty. If any of
If I have about 2000 record and I make a multiple insert. Which method
I have just started creating my first website, which is backed by a database
In Java, suppose I have a method that takes in two lists of integers,
I have written a simple application which has login page. After login search insertion

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.