Listing 910 srccomcookbookdataMyDBhelperjava


import android.content.Context;

import android.database.sqlite.SQLiteDatabase;

import android.database.sqlite.SQLiteException;

import android.database.sqlite.SQLiteOpenHelper;

import android.database.sqlite.SQLiteDatabase.CursorFactory;

import android.util.Log;

public class MyDBhelper extends SQLiteOpenHelper{

private static final String CREATE_TABLE="create table "+ Constants.TABLE_NAME+" ("+

Constants.KEY_ID+" integer primary key autoincrement, "+ Constants.TITLE_NAME+" text not null, "+ Constants.CONTENT_NAME+" text not null, "+ Constants.DATE_NAME+" long);";

public MyDBhelper(Context context, String name, CursorFactory factory, int version) { super(context, name, factory, version);

^Override public void onCreate(SQLiteDatabase db) {

Log.v("MyDBhelper onCreate","Creating all the tables"); try {

db.execSQL(CREATE_TABLE); } catch(SQLiteException ex) {

Log.v("Create table exception", ex.getMessage());

^Override public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { Log.w("TaskDBAdapter", "Upgrading from version "+oldVersion +" to "+newVersion

+", which will destroy all old data"); db.execSQL("drop table if exists "+Constants.TABLE_NAME); onCreate(db);

The third file of the package is the Constants class shown in Listing 9.11.This class is used to hold all the String constants because they are utilized in both MyDB and MyDBhelper.

Character Building Thought Power

Character Building Thought Power

Character-Building Thought Power by Ralph Waldo Trine. Ralph draws a distinct line between bad and good habits. In this book, every effort is made by the writer to explain what comprises good habits and why every one needs it early in life. It draws the conclusion that habits nurtured in early life concretize into impulses in future for the good or bad of the subject.

Get My Free Ebook

Post a comment