mardi 3 novembre 2015

Creating databse, adding string in to it and, dispalying

i am learning android like i just started,so i was trying out something i know it might be so simple but i am not able to do it.so i am mentioning what i need.1) I WANT TO CREATE A DATA BASE 2) PUTTING QUESTIONS / STRING directly in to database 3) I WANT TO SEE THAT STRING IN A PAGE as a text view or something

ublic class OpenHelper extends SQLiteOpenHelper {

public static final String LOGCAT = "SOLACE";

public static final String DATABASE_NAME = "SOLACE.db";
public static final int DATABASE_VERSION = 1;





public static final String TABLE_QUESTION = "question";
public static final String COLUMN_QUESTION_ID = "questionId";
public static final String COLUMN_QUESTION = "question";







private static final String TABLE_QUESTION_CREATE = "CREATE TABLE " + TABLE_QUESTION + "(" +
        COLUMN_QUESTION_ID + " INTEGER PRIMERY KEY AUTOINCEMENT, " + COLUMN_QUESTION + " TEXT " + ")";






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

}


@Override
public void onCreate(SQLiteDatabase db) {

    db.execSQL(TABLE_QUESTION_CREATE);


    Log.i(LOGCAT, "Table has been created");
}


@Override
public void onUpgrade(SQLiteDatabase db, int arg1, int arg2) {

    db.execSQL("DROP TABLE IF EXISTS "+ TABLE_QUESTION);
    onCreate(db);
}

}

Aucun commentaire:

Enregistrer un commentaire