Reputation: 123
public class DatabaseHelper extends SQLiteOpenHelper {
public static final String DATABASE_NAME = "Student.db";
public static final String TABLE_NAME = "student_table";
public static final String COL_1 = "ID";
public static final String COL_2 = "NAME";
public static final String COL_3 = "SURNAME";
public static final String COL_4 = "MARKS";
public static final String COL_5 = "DATETIMEZ";
public Cursor NAME_MARKS() {
SQLiteDatabase db = this.getWritableDatabase();
Cursor res = db.rawQuery("select * from " + TABLE_NAME, null);
//does not work
Cursor res = db.rawQuery("select COL_2,COL_3 from " + TABLE_NAME, null);{}
Upvotes: 0
Views: 839
Reputation: 311028
col_2
and col_3
are the names of the variables, not the columns in the database. If you want to use them, you'll need to use some sort of string manipulation/concatination. E.g.:
Cursor res =
db.rawQuery("select " + COL_2 + ", " + COL_3 + " from " + TABLE_NAME, null);
Upvotes: 1