I am absolute beginner to Android. Now I start developing a tutorial project and working with Sqlite database. Now I am retrieving records using where on date column in database. But it is retrieving nothing. Please what is wrong with my code ? How can I correct it please ?
This is the create statement in database helper class
private static final String CREATE_TABLE = "CREATE TABLE "+TABLE_NAME+" ("+COLUMN_ID+" INTEGER PRIMARY KEY AUTOINCREMENT,"+COLUMN_DESCRIPTION+" TEXT,"+
COLUMN_DATE+" DATE,"+COLUMN_DONE+" BOOLEAN)";
This is how I am retrieving record using where clause on date column
String date = "04-22-2014";
ArrayList<Task> tasks = new ArrayList<Task>();
db = getReadableDatabase();
String query = "SELECT * FROM "+TABLE_NAME + " where "+ COLUMN_DATE + " = "+ date;
Cursor cursor = db.rawQuery(query,null);
if(cursor.moveToFirst())
{
do{
Task task = new Task();
task.setId(cursor.getInt(0));
task.setDescription(cursor.getString(1));
task.setDate(cursor.getString(2));
task.setDone(Boolean.valueOf(cursor.getString(3)));
tasks.add(task);
}
while(cursor.moveToFirst());
}
return tasks;
But it is not returning any record. Please what is wrong with code. Help me.
Aucun commentaire:
Enregistrer un commentaire