Popular Posts

There was an error in this gadget

Jan 28, 2012

Using SQLite in Android

It is very easy to use sqllite in android.i have made a small project to use sqlite.. and try to explain it.. so that you can easily use sqllite in android..you can insert and fetch the data from sqlite.

- First create a project named it SQLite
- Open java file
- Type the code in onCreate Block

        SQLiteDatabase db = openOrCreateDatabase("MyDB", MODE_PRIVATE, null);
        db.execSQL("CREATE TABLE IF NOT EXISTS MyTable(LastName VARCHAR(255), FIRSTName VARCHAR(255), Age INT(3))");
       
        db.execSQL("INSERT INTO MyTable VALUES ('Jubayer','Ahmed',25)");
        db.close();

- Now run the project

- To Check the sqllite file Go to DDMS
- open data -> data-> project->databases you can see the sqlite file
- To fetch the data from SQLlite use the code below


    Cursor c = db.rawQuery("SELECT * FROM MyTable", null);
        c.moveToFirst();
        Log.d("Name", c.getString(c.getColumnIndex("LastName")));




No comments:

Post a Comment