【问题标题】:Retrieving a single column or two columns in android studio from sqlite从 sqlite 检索 android studio 中的单列或两列
【发布时间】:2017-10-12 07:22:07
【问题描述】:
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);{}

【问题讨论】:

    标签: java sqlite android-studio android-sqlite


    【解决方案1】:

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

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

    【讨论】:

    • 我的应用程序崩溃不幸停止
    猜你喜欢
    • 1970-01-01
    • 2020-04-10
    • 1970-01-01
    • 2018-05-23
    • 2015-05-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多