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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T02:45:10+00:00 2026-05-16T02:45:10+00:00

Simple enough question, but I cant find ant half-decent documentation on it. Right so

  • 0

Simple enough question, but I cant find ant half-decent documentation on it. Right so I’ve created my SQLite db but it has two problems or one depending how you look at it! The db creates fine and I can show the data in a basic listview, however on changing the orientation of the phone/emulator the insert statements run again and duplicate all the records. Im guessing this has something to do with all the code being placed within the OnCreate() method.
My main question however is how to do INSERT UNIQUE or query the db to see if the record exists? I just could find any good documentation on SQLite DB parameters on the Android platform.

Any help is much obliged !

Cheers

  • 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-05-16T02:45:10+00:00Added an answer on May 16, 2026 at 2:45 am

    You should make use of the DatabaseUtils.stringForQuery() static method that is already in Android SDK to easily retrieve a value, this example is for String bot there is also method for Long

    stringForQuery(SQLiteDatabase db, String query, String[] selectionArgs)
    

    Utility method to run the query on the db and return the value in the first column of the first row.

    Something like

    String myString=DatabaseUtils.stringForQuery(getDB(),query,selectionArgs);
    

    This example was to get a string value, but you can easily adapt to get a Long value, and your query should be something like

    select count(*) from mytable where field1='stringtocheckagainst'
    

    if this returns a number greater the zero, then the field already exists in the database.

    Also look into code for handling orientation changes.


    UPDATE by @nutone:

    On API 11 and higher, you can also use the DatabaseUtils.queryNumEntries functions to get the number of (filtered) rows directly.

    long count = DatabaseUtils.queryNumEntries(getDB(), table, query, selectionArgs);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Seems like a simple enough question but I can't seem to find the answer.
Seemingly a simple enough question, but I cannot work it out. I want to
Well, it seems simple enough, but I can't find a way to add a
This probably has a simple answer, but I must not have had enough coffee
I know is a rather simple question but I just can't find an appropriate
I've got a simple enough question, but no guidance yet through the forums or
I hope this is a simple enough question for any SQL people out there...
I am looking for a simple but good enough Named Entity Recognition library (and
My experience with MySQL is very basic. The simple stuff is easy enough, but
If I had a normal website this would be a simple enough fix... but

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.