Using Android Studio Crating a Database (SQLite)
1. NEW PROJECT
2.CREATE A CLASS NAME CALL (DB.class)
3.import SQLiteDatabase
import SQLiteOpenHelper
SCREEN SHOT OF CODE (IMAGE)
1. NEW PROJECT
2.CREATE A CLASS NAME CALL (DB.class)
3.import SQLiteDatabase
import SQLiteOpenHelper
SCREEN SHOT OF CODE (IMAGE)
CODE (TEXT) Bellow
package com.example.rimzan.j2program;
import android.content.Context;import android.database.sqlite.SQLiteDatabase;import android.database.sqlite.SQLiteOpenHelper;
public class DB extends SQLiteOpenHelper {
public static final String DATABASE_NAME="Student.db"; public static final String TABLE_NAME="Student_Table", COL_1="ID",COL_2="NAME",COL_3="SURENAME",COL_4="MARKS";
public DB(Context context) {
super(context, DATABASE_NAME,null,1); SQLiteDatabase db=getWritableDatabase(); }
@Override public void onCreate(SQLiteDatabase db) {
db.execSQL("CREATE TABLE "+TABLE_NAME+" (ID INTEGER PRIMARY KEY AUTOINCREMENT, " +
"NAME TEXT, SURENAME TEXT, MARKS INTEGER)"); }
@Override public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
db.execSQL("DROP TABLE IF EXISTS "+TABLE_NAME+ ""); onCreate(db); }
}
Comments
Post a Comment