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

The Archive Base Latest Questions

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

String new_recorded_lastname=a lastname; ////record to database…… Cursor cursor = db.rawQuery(SELECT lastname FROM people; ,null);

  • 0
    String new_recorded_lastname="a lastname";
    ////record to database......
    Cursor cursor = db.rawQuery("SELECT lastname FROM people; ",null);

     if (cursor != null){
  while(cursor.moveToNext()){

    String recorded_lastname=cursor.getString(cursor.getColumnIndex("lastname"));
    if(!(recorded_lastname.equals(new_recorded_lastname))){ 
    //add new_recorded_lastname to database
    break;
    }
    }
    }

I want to have a lastname only once in my database.
Even though I check with “if(!(recorded_lastname.equals(new_recorded_lastname)))” this line code to, it adds same records again and again. How can I control a lastname to add only once?

//It works for the first record very well, but starting from the second record, it adds some lastname again and again….

  • 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-04T03:02:03+00:00Added an answer on June 4, 2026 at 3:02 am

    It seems to me that you are checking every record in the database, and as soon as you find one that does not contain the given lastname you add the record to the database. You should accumulate the results of the checks, something like this:

    boolean lastnamePresent = false;
    while(cursor.moveToNext()){
        String recorded_lastname=cursor.getString(cursor.getColumnIndex("lastname"));
        if(recorded_lastname.equals(new_recorded_lastname)){ 
            lastnamePresent = true;
            break;
        }
    }
    
    if(!lastnamePresent)
        // add new_record_lastname to database
    

    Though it would sure be better if you use SQLite tools to handle this kind of stuff. Like setting the column to UNIQUE.

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

Sidebar

Related Questions

String[] toppings = new String[10]; BigDecimal toppingsPrice = null; toppings[0] = req.getParameter(extraCheese); toppings[1] =
As the title said I am bringing in a date string from a datatable
I am getting an error while inserting data into a database. The error is:
I'm having a problem with summing floats properly from my SQLite database. I have
I am trying record from the AudioRecorder then I am trying to play the
When i declare string x = new string(new char[0]); It works fine.My question is
I'm wondering why the following code doesn't work: String test = new String(new byte[]
String[] a = c.toArray(new String[0]); First: Do I need type cast here? (I think
String class has a constructor: new String(byte[] bytes, Charset charset) and a method: byte[]
I have a string array: string[] authors = new string[3]; authors[0] = Charles Dickens;

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.