Search code examples
androidsqlitecursorwhere-clause

SQLite database Where clause not working for text datatype Android


I want to write a Where clause for Sqlite db & my query is as follows,

Cursor cursor = database.query(table_name,new String[]{COLUMN_1,COLUMN_2,COLUMN_3}, COLUMN_1='1', null, null, null, null);

//COLUMN_1='1' is my WHERE Clause & its datatype is text   

I am not able to execute this query & its giving Nullpointer exception immediately after this statement.
I dont know the reason I think there is some problem with text datatype.

I have spent almost half a day searching for the solution but disappointed.

PS: I've also tried using ,

Cursor cursor = database.query(table_name,new String[]{COLUMN_1,COLUMN_2,COLUMN_3}, COLUMN_1=?, new String[] {'1'}, null, null, null);

LogCat:

Below is my LogCat

But Same problem.


Solution

  • Do you initialize the database? Do you have anything like this:

    database = new DBAdapter(this);
    

    Also you need to open the database before the query.

    database.open();