如何获得与光标单排在android系统?(how to GET the SINGLE ROW wi

2019-07-28 20:07发布

我想从databas这名=辞典获取该行,但给了错误的语法谁能告诉我什么是及彼单列正确的语法是我的数据库类代码

public void getdata()
{


     Cursor cursor = myDataBase.query("emp", new String[] {"email","name"}, " name='jiten'",new String[]{}, null, null, null);

     Log.e("running", "cursor run");



     if(cursor!=null)
     {

         Log.e("running", "curosr is not null");
     while(cursor.moveToFirst())
     {

         Log.e("running", "curosr while loop enter");

         String temp =  (cursor.getString(cursor.getColumnIndex(email)));
             String temp2 =(cursor.getString(cursor.getColumnIndex(name)));
        Log.e("running", "id  email" +temp+ " name"+temp2);

    }
 }
}

Answer 1:

你缺少selectionArgs两个

   public Cursor query (String table, String[] columns, String selection, String[] selectionArgs, String groupBy, String having, String orderBy, String limit)

您可能会包括哪些内容?在选择s,这将由selectionArgs两个值来代替,以使他们出现在选择。 该值将被绑定为字符串。

http://developer.android.com/reference/android/database/sqlite/SQLiteDatabase.html

在你的情况将是:

 Cursor cursor = myDataBase.query("emp", new String[] {"email","name"}, "name=?",new String[]{"jiten"}, null, null, null);


文章来源: how to GET the SINGLE ROW with cursor in android?