1

我想从数据库中获取名称 = jiten 但语法错误的行 谁能告诉我获取单行的正确语法是我的数据库类代码

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

    }
 }
}
4

1 回答 1

3

您缺少 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);
于 2012-04-07T13:58:05.170 回答