arnp
arnp

Reputation: 3208

How to find the a value is existing or not in sqlite3?

I am using sqlite database for android development. I should not have the repeatation of records with a same username so that i need to check is that username is existing or not in the database. For that i got a solution called count query. Can i get how to use the count query in sqlite.

Upvotes: 0

Views: 58

Answers (1)

Paresh Mayani
Paresh Mayani

Reputation: 128428

You can use rawQuery, something like:

final String SQL_STATEMENT = "SELECT COUNT(*) FROM users WHERE uname=?";

private void someMethod() {
    Cursor c = db.rawQuery(SQL_STATEMENT, new String[] { username });
    ...
}

Upvotes: 1

Related Questions