Copyright (c) 2013, Uthcode
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
* Redi...
If you think the Android project android_tutorial_projects listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
Java Source Code
package com.uthcode.testdatabaseactivity;
//fromwww.java2s.comimport android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;
/**
* Created by skumaran on 12/29/13.
*/publicclass MySQLiteHelper extends SQLiteOpenHelper{
publicstaticfinal String TABLE_COMMENTS = "comments";
publicstaticfinal String COLUMN_ID = "_id";
publicstaticfinal String COLUMN_COMMENT = "comment";
privatestaticfinal String DATABASE_NAME = "comments.db";
privatestaticfinalint DATABASE_VERSION = 1;
privatestaticfinal String DATABASE_CREATE = "create table "
+ TABLE_COMMENTS + "(" + COLUMN_ID
+ " integer primary key autoincrement, " + COLUMN_COMMENT
+ " text not null); ";
@Override
publicvoid onCreate(SQLiteDatabase sqLiteDatabase) {
sqLiteDatabase.execSQL(DATABASE_CREATE);
}
public MySQLiteHelper(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}
@Override
publicvoid onUpgrade(SQLiteDatabase sqLiteDatabase, int i, int i2) {
Log.w(MySQLiteHelper.class.getName(), "Upgrading database from version " + i + "to" + i2 + " which will destroy data");
sqLiteDatabase.execSQL("DROP TABLE IF EXISTS " + TABLE_COMMENTS);
onCreate(sqLiteDatabase);
}
}