Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I am using SQLite Database in Android. I have used rawQuery in SQLite database. My Database method for that is as follows:

public Cursor selectedDate(String from_dt ,String to_dt) 
{
    try
    {
        String str_k="select RowId,Bill_Date from  SalesMaster Where Bill_Date between '"+
                         from_dt+ "'and'"+to_dt+ "'";
        System.out.println(str_k);

        Cursor c1 = sqldb.rawQuery(
                        "select RowId from  SalesMaster Where Bill_Date between '"+
                        from_dt+ "'and'"+to_dt+ "'", null);
        return c1; 
    }
    catch(Exception e)
    { 
        System.out.println("inside database file "+ e);
        return null;
    }
}

and my .java file is

public void ReportSell(String from_dt,String to_dt)
{
    System.out.println("report selling method has been called");
    String RowId="";
    item db1 = new item(getBaseContext());
    db1.openDb();

    try
    {
        final Cursor cursor = db1.selectedDate(from_dt, to_dt);

        if(cursor.moveToFirst())
        {
            do
            {
                RowId= cursor.getString(cursor.getColumnIndex("RowId")).toString();
                System.out.println("inside java Row Id  file "+ RowId);
                salesid.add(RowId);
                ArrayAdapter <String> adapter = new ArrayAdapter <String>(this, 
                                                     android.R.layout.simple_list_item_1,
                                                     salesid);
            } while(cursor.moveToNext());
        }
        else
        {
            Toast.makeText(getApplicationContext(), "No data found",
                               Toast.LENGTH_LONG).show();  
        }
    } catch(Exception e) 
    {
        System.out.println("inside java file "+ e);
    }
    db1.closeDb(); 
}

The main problem is that it will return RowId from salesMaster table as per from-date and to-date, but actual problem is it will return values but not include last to-date.

For example, if I want to RowId from 25/02/2015 to 28/02/2015 so it will give RowId from 25/02/2015 to 27/02/2015 but not included 28/02/2015.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
271 views
Welcome To Ask or Share your Answers For Others

1 Answer

You have to replace between to

Expression (min <= expr AND expr <= max)

Change you query to

 String str_k="SELECT * from TABLE_NAME Where COLUMN_NAME >='"+from_date+ "' AND <= '"+to_date+ "'";

            System.out.println(str_k);

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...