Friday, 1 June 2012

Android Sqlite Connection


1.This Code helps to create a sqlite databse

/*----------------------------open and create database----------------------------------*/

package com.sqliteexample;

import android.app.Activity;
import android.os.Bundle;
import android.database.sqlite.SQLiteDatabase;

public class SQLiteTest extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
SQLiteDatabase db;
db = openOrCreateDatabase(
"RefisoftDb.db"
, SQLiteDatabase.CREATE_IF_NECESSARY
, null
);
}
}
/*--------------------------------------------------------------*/
2.open command prompt

C:\Android\android-sdk\platform-tools>adb devices
List of devices attached
emulator-5554 device

To view the database create we have to log into adb shell,for this in command prompt
C:\Android\android-sdk\platform-tools>adb -s emulator-5554 shell
# ls /data/data/com.sqliteexample/databases
RefisoftDb.db
# sqlite3 /data/data/example.SQLiteTest/databases/TestData.db

3 comments: