Android SQLite SELECT Query

后端 未结 6 1276
我寻月下人不归
我寻月下人不归 2020-12-30 00:03

I have taken String value from a EditText and set it inside SELECT QUERY after WHERE condition

As

TextView tv          


        
6条回答
  •  再見小時候
    2020-12-30 00:26

    Detailed answer:

    String[] selectionArgs = new String[]{name};
        Cursor c = db.rawQuery(" SELECT * FROM " + tabl1 + " WHERE " + name + " = ? ", selectionArgs);
    

    selectionArgs : this takes the 'name' you desire to compare with, as argrument.

    Here note "A Cursor object, which is positioned before the first entry of the table you refer to".

    So,to move to first entry :

        c.moveToFirst();
    

    getColumnIndex(String ColumnName) : this returns the zero-based column index for the given column name.

    tv.setText(c.getString(c.getColumnIndex("email")));
    

    In case, you want to go searching through multiple rows for a given name under 'name' column then use loop as below:

    if (cursor.moveToFirst()){
            do{
                ////go traversing through loops
               
            }while(cursor.moveToNext());
    
        
    

    This should solve the problem.

提交回复
热议问题