haiii
i will send some code for go thro in that and make the one object of that
one in u r activity class and use this...




import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.SQLException;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;
/**
 * Simple notes database access helper class. Defines the basic CRUD
operations
 * for the notepad example, and gives the ability to list all notes as well
as
 * retrieve or modify a specific note.
 *
 * This has been improved from the first version of this tutorial through
the
 * addition of better error handling and also using returning a Cursor
instead
 * of using a collection of inner classes (which is less scalable and not
 * recommended).
 */
public class NotesDbAdapter {
    public static final String KEY_TITLE = "title";
    public static final String KEY_BODY = "body";
    public static final String KEY_ROWID = "_id";
    private static final String TAG = "NotesDbAdapter";
    private DatabaseHelper mDbHelper;
    private static SQLiteDatabase mDb;
   static boolean firsttime=false;
    /**
     * Database creation sql statement
     */
    private static final String DATABASE_CREATE =
            "create table notes (_id integer primary key autoincrement, "
                    + "title text not null, body text not null);";
    private static final String DATABASE_NAME = "Nightdtdb";
    private static final String DATABASE_TABLE = "notes";
    private static final int DATABASE_VERSION = 2;

    private final Context mCtx;
    private static class DatabaseHelper extends SQLiteOpenHelper {
        DatabaseHelper(Context context) {

            super(context, DATABASE_NAME, null, DATABASE_VERSION);

        }
        @Override
        public void onCreate(SQLiteDatabase db) {
         firsttime=true;
           db.execSQL(DATABASE_CREATE);



        }
        @Override
        public void onUpgrade(SQLiteDatabase db, int oldVersion, int
newVersion) {
            Log.w(TAG, "Upgrading database from version " + oldVersion + "
to "
                    + newVersion + ", which will destroy all old data");
            db.execSQL("DROP TABLE IF EXISTS notes");
            onCreate(db);
        }
    }
    public NotesDbAdapter(Context ctx) {
        this.mCtx = ctx;

    }

    public NotesDbAdapter open() throws SQLException {
        mDbHelper = new DatabaseHelper(mCtx);
        mDb = mDbHelper.getWritableDatabase();
        return this;
    }

    public void close() {
        mDbHelper.close();
    }
    public void createNote(String title, String body) {

      ContentValues initialValues = new ContentValues();
   initialValues.put(KEY_TITLE, title);
         initialValues.put(KEY_BODY, body);
         mDb.insert(DATABASE_TABLE, null, initialValues);

      }

    public static void createNotefirsttime() {

     if(firsttime==true){

     String title1 = null,body1 = null;
    for(int i=1;i<8;i++){
        ContentValues initialValues = new ContentValues();
         if(i==1){
         title1="bule";
         body1="bule";
         initialValues.put(KEY_TITLE, title1);
            initialValues.put(KEY_BODY, body1);
            mDb.insert(DATABASE_TABLE, null, initialValues);
         }


    }
     }
     }

    public boolean deleteNote(long rowId) {
        return mDb.delete(DATABASE_TABLE, KEY_ROWID + "=" + rowId, null) >
0;
    }

    public Cursor fetchAllNotes() {
        return mDb.query(DATABASE_TABLE, new String[] {KEY_ROWID, KEY_TITLE,
                KEY_BODY}, null, null, null, null, null);
    }
    public Cursor fetchNote(long rowId) throws SQLException {

       Cursor mCursor =
             mDb.query(true, DATABASE_TABLE, new String[] {KEY_ROWID,
                     KEY_TITLE, KEY_BODY}, KEY_ROWID + "=" + rowId, null,
                     null, null, null, null);
     if (mCursor != null) {

         mCursor.moveToFirst();
     }
     else{

     }
     return mCursor;
 }

    public void updateNote1(String title, String body) {
      ContentValues args = new ContentValues();
     int rowId1=1;
      args.put(KEY_TITLE, title);
     args.put(KEY_BODY, body);
     mDb.update(DATABASE_TABLE, args, KEY_ROWID + "=" + rowId1, null);

 }
    public void secupdateNote(String title, String body) {
        ContentValues args = new ContentValues();
       int rowId1=2;
        args.put(KEY_TITLE, title);
       args.put(KEY_BODY, body);
       mDb.update(DATABASE_TABLE, args, KEY_ROWID + "=" + rowId1, null);

   }

}




haiii
i will send some code for go thro in that and make the one object of that
one in u r activity class and use this...



package com.night;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.SQLException;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;
/**
 * Simple notes database access helper class. Defines the basic CRUD
operations
 * for the notepad example, and gives the ability to list all notes as well
as
 * retrieve or modify a specific note.
 *
 * This has been improved from the first version of this tutorial through
the
 * addition of better error handling and also using returning a Cursor
instead
 * of using a collection of inner classes (which is less scalable and not
 * recommended).
 */
public class NotesDbAdapter {
    public static final String KEY_TITLE = "title";
    public static final String KEY_BODY = "body";
    public static final String KEY_ROWID = "_id";
    private static final String TAG = "NotesDbAdapter";
    private DatabaseHelper mDbHelper;
    private static SQLiteDatabase mDb;
   static boolean firsttime=false;
    /**
     * Database creation sql statement
     */
    private static final String DATABASE_CREATE =
            "create table notes (_id integer primary key autoincrement, "
                    + "title text not null, body text not null);";
    private static final String DATABASE_NAME = "Nightdtdb";
    private static final String DATABASE_TABLE = "notes";
    private static final int DATABASE_VERSION = 2;

    private final Context mCtx;
    private static class DatabaseHelper extends SQLiteOpenHelper {
        DatabaseHelper(Context context) {

            super(context, DATABASE_NAME, null, DATABASE_VERSION);

        }
        @Override
        public void onCreate(SQLiteDatabase db) {
         firsttime=true;
           db.execSQL(DATABASE_CREATE);



        }
        @Override
        public void onUpgrade(SQLiteDatabase db, int oldVersion, int
newVersion) {
            Log.w(TAG, "Upgrading database from version " + oldVersion + "
to "
                    + newVersion + ", which will destroy all old data");
            db.execSQL("DROP TABLE IF EXISTS notes");
            onCreate(db);
        }
    }
    public NotesDbAdapter(Context ctx) {
        this.mCtx = ctx;

    }

    public NotesDbAdapter open() throws SQLException {
        mDbHelper = new DatabaseHelper(mCtx);
        mDb = mDbHelper.getWritableDatabase();
        return this;
    }

    public void close() {
        mDbHelper.close();
    }
    public void createNote(String title, String body) {

      ContentValues initialValues = new ContentValues();
   initialValues.put(KEY_TITLE, title);
         initialValues.put(KEY_BODY, body);
         mDb.insert(DATABASE_TABLE, null, initialValues);

      }

    public static void createNotefirsttime() {

     if(firsttime==true){

     String title1 = null,body1 = null;
    for(int i=1;i<8;i++){
        ContentValues initialValues = new ContentValues();
         if(i==1){
         title1="bule";
         body1="bule";
         initialValues.put(KEY_TITLE, title1);
            initialValues.put(KEY_BODY, body1);
            mDb.insert(DATABASE_TABLE, null, initialValues);
         }


    }
     }
     }

    public boolean deleteNote(long rowId) {
        return mDb.delete(DATABASE_TABLE, KEY_ROWID + "=" + rowId, null) >
0;
    }

    public Cursor fetchAllNotes() {
        return mDb.query(DATABASE_TABLE, new String[] {KEY_ROWID, KEY_TITLE,
                KEY_BODY}, null, null, null, null, null);
    }
    public Cursor fetchNote(long rowId) throws SQLException {

       Cursor mCursor =
             mDb.query(true, DATABASE_TABLE, new String[] {KEY_ROWID,
                     KEY_TITLE, KEY_BODY}, KEY_ROWID + "=" + rowId, null,
                     null, null, null, null);
     if (mCursor != null) {

         mCursor.moveToFirst();
     }
     else{

     }
     return mCursor;
 }

    public void updateNote1(String title, String body) {
      ContentValues args = new ContentValues();
     int rowId1=1;
      args.put(KEY_TITLE, title);
     args.put(KEY_BODY, body);
     mDb.update(DATABASE_TABLE, args, KEY_ROWID + "=" + rowId1, null);

 }
    public void secupdateNote(String title, String body) {
        ContentValues args = new ContentValues();
       int rowId1=2;
        args.put(KEY_TITLE, title);
       args.put(KEY_BODY, body);
       mDb.update(DATABASE_TABLE, args, KEY_ROWID + "=" + rowId1, null);

   }

}



---------- Forwarded message ----------
From: sharman sengar <sharma...@gmail.com>
Date: Thu, Apr 9, 2009 at 12:17 PM
Subject: [android-beginners] how to connect Android with Sqlite3.
To: android-beginners@googlegroups.com



Dear Group,
                     Actually i m working in an Android application on which
i want to connect the Android with Sqlite3.0.i wrote the code for connecting
that one,but not connected,plz help me....
-- 
Thanks and  Regards
Sharman Singh Sengar






-- 
Anand M Joseph
Software Engineer
Aymex Services Pvt. Ltd.
Cherukomorothu Road,
Mamangalam, Palarivattom P.O.,
Kochi – 682 025,
Kerala, India
Tel: +91 484 405 5750 / 405 5285 / 405 5725
Mob:919744343272
E-mail   :  anandmampuzha...@gmail.com

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Beginners" group.
To post to this group, send email to android-beginners@googlegroups.com
To unsubscribe from this group, send email to
android-beginners-unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-beginners?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to