2017-10-12 63 views
0
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); 

在Android Studio中两列//不起作用检索单个列或从sqlite的

Cursor res = db.rawQuery("select COL_2,COL_3 from " + TABLE_NAME, null);{} 

回答

1

col_2col_3变量,而不是在数据库中列的名称。如果你想使用它们,你需要使用某种字符串操作/连接。例如:

Cursor res = 
    db.rawQuery("select " + COL_2 + ", " + COL_3 + " from " + TABLE_NAME, null); 
+0

我的应用崩溃不幸停止 –