dadadodo dadadodo - 3 months ago 9
Android Question

Querying a SQLite table to return rows with a specific ID

This is the method that is suppose to take a

long ID
and return the row that matches the given id but something is wrong with my query and I cannot figure it out. Any ideas? (the column containing the id values is called "ID")

public Cursor getAllData (long ID) {
SQLiteDatabase db = this.getWritableDatabase();
long thisID = ID ;
Cursor result = db.rawQuery("select * from WHERE ID = " + thisID + DataTableName,null);
return result;
}

Answer

You should do it as follows :

Cursor result = db.rawQuery("select * from " + DataTableName + " WHERE ID = "+thisID,null);

And what @Danail Alexiev wanted to say to you I guess is this :

Cursor result = db.rawQuery("select * from " + DataTableName + " WHERE ID = ?",new long[]{thisID});
Comments