Sunday, 18 May 2014

How to connect sqlite database in android

Connect sqlite database in android

Using the Android SQLite Database

Try this

    public class Database extends SQLiteOpenHelper {

private static final int DATABASE_VERSION=1 ;

private static final String DATABASE_NAME="DB_NAME";

public static final String TABLE_NAME="T_NAME";

public static final String FIELD1="field_name";

    public Database(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}


public void onCreate(SQLiteDatabase db) {
String CREATE_TABLE = "CREATE TABLE " +
+"("+TABLE_NAME+ " TEXT,")";
System.out.println(CREATE_TABLE);
db.execSQL(CREATE_TABLE);
}

public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
db.execSQL("DROP TABLE IF EXISTS "+CREATE_TABLE);

onCreate(db);
}


No comments:

Post a Comment