0
SQLiteDatabase db = this.getReadableDatabase();
Cursor mCursor =db.query(TABLE_ACCOUNTS, new String[]{a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s}, null,null, null, null, null);

我的问题是:这个初始化是否允许返回 db 数据库和表中的所有值?

就我的项目而言,它似乎只返回 NULL 值。(无错误)a = null,b = null,c = null

当我用 a+"=?" 操作第三个参数时检测到一些实际值 和变体(现在为空)。

或者防止实际值是别的什么?(假设将数据添加到数据库有效)

(添加代码)

public void addAccount() {
        SQLiteDatabase db = this.getWritableDatabase();
     Account account = new Account();
        ContentValues values = new ContentValues();
        values.put(id, account.getA()); // Contact Name
        values.put(a, account.getA()); // Contact Phone Number
        values.put(b, account.getB()); // Contact Phone Number
        values.put(c, account.getC());
...

        db.insert(TABLE_ACCOUNTS, null, values);
        db.close(); // Closing database connection

    }

(光标代码)

 if ( (mCursor != null && mCursor.moveToFirst()) ) {

            do {
                stringResult1 = 
                        "a: "+ mCursor.getString(0)+ "\n"
                     + "b: " + mCursor.getString(1) + "\n"
                     + "c: " + mCursor.getString(2) + "\n"
                     + "d: " + mCursor.getString(3) + "\n"
                     + "e: " + mCursor.getString(4) + "\n"
                     + "f: " + mCursor.getString(5) + "\n"
                     + "g: " + mCursor.getString(6) + "\n"
                     + "h: " + mCursor.getString(7) + "\n"
                     + "i " + mCursor.getString(8) + "\n"
                     + "j: " + mCursor.getString(9) + "\n"
                     + "k: " + mCursor.getString(10) + "\n"
                     + "l: " + mCursor.getString(11) + "\n"
                     + "m: " + mCursor.getString(12) + "\n"
                     + "n: " + mCursor.getString(13) + "\n"
                     + "o: " + mCursor.getString(14) + "\n"
                     + "p: " + mCursor.getString(15) + "\n"
                     + "q: " + mCursor.getString(16) + "\n"
                     + "r: " + mCursor.getString(17) + "\n"
                     + "s: " + mCursor.getString(18) + "\n";
            } while (mCursor.moveToNext());


        // make sure to close the cursor
        mCursor.close();
    }
4

1 回答 1

0
Cursor mCursor =db.query(TABLE_ACCOUNTS, new String[]{a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s}, null,null, null, null, null);

关于上述查询.. 第二个参数,即字符串数组是投影参数,表示您要从 db 中获取的列并将其填充到光标中。

因为如果在查询中 a,b,c,d,e... 变量的值可能与 db 中的列的值不同,因此游标中不存在所请求列的值。

希望有帮助!谢谢

于 2012-12-24T04:48:24.043 回答