Select query to check the existing record in the SQLite Database in android
I want to know the Query to check whether the particular Record in the DataBase already exi开发者_如何学JAVAsts or not for my application.
I have made one function for these, but it is not working properly.
public boolean ifExisting(String name) {
Cursor c = db.rawQuery("SELECT * FROM " + TABLE_NAME + "WHERE" + "name" + "=" + name, null);
if(c.getCount() == 0)
return false;
else
return true;
}
This is the place where I need to perform the function of checking for the Duplication Process.
if(dh.ifExisting(dataVector.get(position)) == true) {
} else {
dh.insert(dataVector.get(position));
}
Can anybody please help me.
Thanks, david
Can you be a bit more specific? "no working properly" isn't a real problem description.
Anyway, your query is missing some spaces:
"SELECT * FROM " + TABLE_NAME + "WHERE" + "name" + "=" + name
// if you would print the string you would get this:
"SELECT * FROM TABLE_NAMEWHEREname=name"
First question: your data.Vector.get(position)
returns a string as result?
Second: if your rawquery doesn't works, then try:
" where " + name + " like '"
+ name + "'", null);
Maybe this might help you
Cursor c = db.rawQuery("SELECT * FROM " + TABLE_NAME + "WHERE" + "name" + "=" + name, null);
>TABLE_NAME + "WHERE" + "name"
will be "TablenameWHEREname" instead of "Tablename WHERE name".
精彩评论