Udhaya Udhaya - 9 days ago 5
Android Question

How to get the next data from sqlite in android

I'm using sqlite for my fm app.I want to retrieve the next upcoming 3 data from the database using Current time.

My columns are:

db.execSQL("CREATE TABLE IF NOT EXISTS proname(ID INTEGER PRIMARY KEY AUTOINCREMENT,ImageID INTEGER,Title TEXT,FromTiming INTEGER,ToTiming INTEGER);");


please help me in writting query for this condition

Answer

Fetch data using:

public Cursor fetchMSG(int tId){
        SQLiteDatabase sqdb=getReadableDatabase();
        return  sqdb.rawQuery("select * from proname where "+KEY_FROMTIME+"=" + tId+  " ASC limit 3 ", null);

    }

and insert data like:

public void insertMSG(String imgId,String title,int fromtime,int totime){
        SQLiteDatabase sqdb=getWritableDatabase();
        sqdb.beginTransaction();
        try{
            ContentValues values= new ContentValues();
            values.put(KEY_IMGID,imgId);
            values.put(KEY_TITLE,title);
            values.put(KEY_FROMTIME,fromtime);
            values.put(KEY_TOTIME,totime);

            sqdb.insert("proname",null,values);

            sqdb.setTransactionSuccessful();
        }catch (Exception ee){ee.printStackTrace();}
        finally {
            sqdb.endTransaction();
            sqdb.close();
        }
    }