RSS

Create SQLite Database in Android

28 Feb

package com.my.first;

import android.R.string;
 import android.app.Activity;
 import android.database.Cursor;
 import android.database.sqlite.SQLiteDatabase;
 import android.os.Bundle;
 import android.util.Log;

public class DatabaseActivity extends Activity {

@Override
 public void onCreate(Bundle savedInstanceState) {
 super.onCreate(savedInstanceState);
 setContentView(R.layout.main);

SQLiteDatabase db = openOrCreateDatabase("MyDB", MODE_PRIVATE, null);
 db.execSQL("CREATE TABLE IF NOT EXISTS MyTable (FirstName VARCHAR,LastName VARCHAR,Age INT(3))");
 db.execSQL("INSERT INTO MyTable VALUES('Josh','Fedric',23)");

Cursor c = db.rawQuery("SELECT * FROM MyTable", null);
 c.moveToFirst();
 String msg = c.getString(c.getColumnIndex("FirstName"));
 Log.d("Fname",msg);

}
 }

Advertisements
 
Leave a comment

Posted by on February 28, 2012 in Android

 

Tags: ,

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: