You have to do 2 things:

*1. Create your class relate Database a Table you want create*

package com.angelo.sqllite;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

public class MioDatabaseHelper extends SQLiteOpenHelper {
private static final String DB_NAME = "minchiature_db";
private static final int DB_VERSION = 1;
public MioDatabaseHelper(Context context) {
super(context, DB_NAME, null, DB_VERSION);
}

@Override
public void onCreate(SQLiteDatabase db) {
    String sql = "";
    sql += "CREATE TABLE agenda (";
    sql += " _id INTEGER PRIMARY KEY,";
    sql += " nome TEXT NOT NULL,";
    sql += " cognome TEXT NOT NULL,";
    sql += " telefono TEXT NOT NULL";
    sql += ")";
    db.execSQL(sql);
    }

@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
// Aggiornamento delle tabelle
}


}

*2.Use Your activity *

package com.angelo.sqllite;

import android.app.Activity;
import android.content.ContentValues;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.util.Log;

public class TestSqlLiteActivity extends Activity
{
    private MioDatabaseHelper mioDatabaseHelper;
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

 /***********CREATE A
DATABASE******************************************************/

        mioDatabaseHelper = new MioDatabaseHelper(this);
        SQLiteDatabase db = mioDatabaseHelper.getWritableDatabase();
        ContentValues values = new ContentValues();

        values.put("nome", "Mario");
        values.put("cognome", "Rossi");
        values.put("telefono", "061299178");
        long id = db.insert("agenda", null, values);

        values.put("nome", "Mario2");
        values.put("cognome", "Rossi2");
        values.put("telefono", "0612991782");
        id = db.insert("agenda", null, values);

        values.put("nome", "Mario3");
        values.put("cognome", "Rossi3");
        values.put("telefono", "0612991783");
        id = db.insert("agenda", null, values);


        String query = "SELECT _id FROM agenda WHERE cognome = ? ORDER BY
_id ASC";
        String[] selectionArgs3 = { "Rossi" };
        // I cursori sono gli oggetti di Android che permettono di navigare
all’interno di un result set, ossia
        //nell’insieme dei risultati restituiti da una query.
        Cursor cursor = null;
        cursor = db.rawQuery(query, selectionArgs3);

        int count = cursor.getCount();

        System.out.println("il numero di dati contenuti nel database "+
count);

        while (cursor.moveToNext()) {

            id = cursor.getLong(0);
            System.out.println("Questo è l'ID ====>"+id);
            String nome = cursor.getString(1);
            System.out.println("Questo è l'ID ====>"+nome);
            String cognome = cursor.getString(2);
            System.out.println("Questo è il COGNOME ====>"+cognome);

        }



 /***********DROP
TABLE***************************************************************/

        db.execSQL("DROP TABLE agenda");

    }

}




On Thu, Aug 16, 2012 at 9:55 AM, Live Happy <livehap...@gmail.com> wrote:

> may this well help you
> http://www.vogella.com/articles/AndroidSQLite/article.html
> On Thu, Aug 16, 2012 at 10:52 AM, RichardC <richard.crit...@googlemail.com
> > wrote:
>
>> android-sdk\samples\android-16\NotePad
>>
>> On Thursday, August 16, 2012 8:00:03 AM UTC+1, Sadhna Upadhyay wrote:
>>>
>>>
>>>
>>>      Hi Everybody,
>>>       please share with me database example
>>>
>>>  --
>> You received this message because you are subscribed to the Google
>> Groups "Android Developers" group.
>> To post to this group, send email to android-developers@googlegroups.com
>> To unsubscribe from this group, send email to
>> android-developers+unsubscr...@googlegroups.com
>> For more options, visit this group at
>> http://groups.google.com/group/android-developers?hl=en
>
>
>  --
> You received this message because you are subscribed to the Google
> Groups "Android Developers" group.
> To post to this group, send email to android-developers@googlegroups.com
> To unsubscribe from this group, send email to
> android-developers+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/android-developers?hl=en
>

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

Reply via email to