使用SqLite Query()参数

时间:2012-12-24 03:56:54

标签: android sqlite

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

使用+“=?”使用第3个参数进行操作时检测到一些实际值和变体(现在为空)。

或者实际价值的预防可能是别的吗? (假设向数据库添加数据工作)

(添加代码)

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();
    }

1 个答案:

答案 0 :(得分: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);

关于上面的查询..第二个参数,即一个String数组是投影参数,是指你想从db中获取并填入游标的列。

因为在查询中,如果a,b,c,d,e ...变量的值可能与db中的列的值不同,那么在游标中对于请求的列没有值。

希望有所帮助!感谢