Skip to content

Instantly share code, notes, and snippets.

@WSAyan
Created July 18, 2017 09:27
Show Gist options
  • Save WSAyan/c01d237afb06477981d504efac3697e4 to your computer and use it in GitHub Desktop.
Save WSAyan/c01d237afb06477981d504efac3697e4 to your computer and use it in GitHub Desktop.
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
public class SqliteDatabseHandler extends SQLiteOpenHelper {
private static final int DATABASE_VERSION = 1;
// Database Name
private static final String DATABASE_NAME = "dbname";
public SqliteDatabseHandler(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}
// Creating Tables
@Override
public void onCreate(SQLiteDatabase db) {
String CREATE_X_TABLE = ""; //create query
db.execSQL(CREATE_X_TABLE);
}
// Upgrading database
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
// Drop older table if existed
db.execSQL("DROP TABLE IF EXISTS " + "TABLE_NAME"); //replace TABLE_NAME with your table names
// Create tables again
onCreate(db);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment