rawQuery(query, selectionArgs)

后端 未结 7 1256
不思量自难忘°
不思量自难忘° 2020-11-30 22:32

I want to use select query for retrieving data from table. I have found, rawQuery(query, selectionArgs) method of SQLiteDatabase class to retrieve

相关标签:
7条回答
  • 2020-11-30 22:40

    see below code it may help you.

    String q = "SELECT * FROM customer";
    Cursor mCursor = mDb.rawQuery(q, null);
    

    or

    String q = "SELECT * FROM customer WHERE _id = " + customerDbId  ;
    Cursor mCursor = mDb.rawQuery(q, null);
    
    0 讨论(0)
  • 2020-11-30 22:41

    One example of rawQuery - db.rawQuery("select * from table where column = ?",new String[]{"data"});

    0 讨论(0)
  • 2020-11-30 22:43

    Maybe this can help you

    Cursor c = db.rawQuery("query",null);
    int id[] = new int[c.getCount()];
    int i = 0;
    if (c.getCount() > 0) 
    {               
        c.moveToFirst();
        do {
            id[i] = c.getInt(c.getColumnIndex("field_name"));
            i++;
        } while (c.moveToNext());
        c.close();
    }
    
    0 讨论(0)
  • 2020-11-30 22:43
    String mQuery = "SELECT Name,Family From tblName";
    Cursor mCur = db.rawQuery(mQuery, new String[]{});
    mCur.moveToFirst();
    while ( !mCur.isAfterLast()) {
            String name= mCur.getString(mCur.getColumnIndex("Name"));
            String family= mCur.getString(mCur.getColumnIndex("Family"));
            mCur.moveToNext();
    }
    

    Name and family are your result

    0 讨论(0)
  • 2020-11-30 22:48
    rawQuery("SELECT id, name FROM people WHERE name = ? AND id = ?", new String[] {"David", "2"});
    

    You pass a string array with an equal number of elements as you have "?"

    0 讨论(0)
  • 2020-11-30 22:54

    if your SQL query is this

    SELECT id,name,roll FROM student WHERE name='Amit' AND roll='7'
    

    then rawQuery will be

    String query="SELECT id, name, roll FROM student WHERE name = ? AND roll = ?";
    String[] selectionArgs = {"Amit","7"} 
    db.rawQuery(query, selectionArgs);
    
    0 讨论(0)
提交回复
热议问题