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);
//不起作用
Cursor res = db.rawQuery("select COL_2,COL_3 from " + TABLE_NAME, null);{}
答案 0 :(得分:1)
col_2
和col_3
是变量的名称,而不是数据库中的列。如果你想使用它们,你需要使用某种字符串操作/连接。 E.g:
Cursor res =
db.rawQuery("select " + COL_2 + ", " + COL_3 + " from " + TABLE_NAME, null);