dimanche 17 janvier 2016

Sqlite select statement results in an error whenever i open the intent

Here is my code

The first 3 functions are in the database class

public void onCreate(SQLiteDatabase db){

        String creation_query3= "CREATE TABLE "
                + TABLE_Doctor + "(" + Doctor_ID
                + " INTEGER PRIMARY KEY," + Doctor_NAME
                + " TEXT, " + Doctor_PHONE + "TEXT )";

        db.execSQL(creation_query3);

    }

public void adddoctor(String pName, String ph){

        SQLiteDatabase db = this.getWritableDatabase();
        ContentValues cv = new ContentValues();
        cv.put(Doctor_NAME,pName);
        cv.put(Doctor_PHONE,ph);
        db.insert(TABLE_Doctor, null, cv);
        db.close();
}

public String getAllDoctors(){

        Cursor cursor = getReadableDatabase().rawQuery("SELECT "+Doctor_NAME+" FROM "+ TABLE_Doctor, null);
        cursor.moveToFirst();

        String s=cursor.getString(cursor.getColumnIndexOrThrow(Doctor_NAME));
        cursor.close();
        return s;           
    }

And this is in the main class

{

String test=db.getAllDoctors();

textView.setText(test.toString());

}

Aucun commentaire:

Enregistrer un commentaire