2

I want to retrieve data between two dates in Android SQLite I used one function in SQLiteAdapter class. My function is

public void history(String startdate,String enddate) {  
   Cursor mCursor = db.rawQuery("SELECT * FROM "+ KK_AIRLINEBOOK + 
                    " WHERE " + KEY_Bookingdate + 
                    " BETWEEN " + startdate + " AND " + enddate , null);        
}

However it doesn't work it shows syntax error near AND

2
  • What is the exact query you are sending to the database? Please edit it into your question. (Also, please use the code button for code formatting in the future - see my edit). Commented Mar 31, 2013 at 12:01
  • @halfer actuly i want to show booking history to user like if user want to know his booking details between particular two dates........what query i need to pass??? please please help me :( :( Commented Mar 31, 2013 at 12:28

1 Answer 1

16

Put literals

public void history(String startdate,String enddate) {  
Cursor mCursor = db.rawQuery("SELECT * FROM "+ KK_AIRLINEBOOK + 
                " WHERE " + KEY_Bookingdate + 
                " BETWEEN '" + startdate + "' AND '" + enddate + "'", null);        
}  

However it is better if you use selectionArgs

public void history(String startdate,String enddate) {  
Cursor mCursor = db.rawQuery("SELECT * FROM "+ KK_AIRLINEBOOK + 
                " WHERE " + KEY_Bookingdate + 
                " BETWEEN ?  AND ?", new String[]{startdate, enddate});        
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.