0

I parsed the json data and put these values in database(Sqlite database). Next time when i open the activity it again parsed the data and put these values in database. so i want to check first whether data is in sqlite?, if so then i need to skip parsing. And just get these values from database. how can i do this?

3
  • 2
    Simple SELECT Query which returns Cursor with data is enough for this. Commented Aug 21, 2012 at 5:21
  • Refer this link stackoverflow.com/questions/11361722/… Commented Aug 21, 2012 at 5:21
  • I'm not sure what you mean. Try to check if you can read data from SQLite: SELECT * FROM YourTable Commented Aug 21, 2012 at 5:22

1 Answer 1

1

Try this.

public int isDataAvailable()
    {
        int total = 0;
        try
        {
            Cursor c = null;
            c = db.rawQuery("select id from mycoupon", null);

            if(c.getCount() != 0)
                total = c.getCount();

            c.close();
        }
        catch(Exception e)
        {
            e.printStackTrace();
        }
        return total; 
    }

If there are no records in table then it returns 0 otherwise returns no of records.

Sign up to request clarification or add additional context in comments.

1 Comment

@Brinda-user1594986 Always Welcome

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.