如何让单列带光标的Andr​​oid? [英] how to GET the SINGLE ROW with cursor in android?

查看:112
本文介绍了如何让单列带光标的Andr​​oid?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从databas该名称的行=辞典 但给出了语法错误,谁能告诉我什么是正确的语法 得到单列 这里是我的code数据库类

 公共无效的getData()
{


     光标光标= myDataBase.query(EMP,新的String [] {电子邮件,名},NAME ='辞典,新的String [] {},NULL,NULL,NULL);

     Log.e(跑,光标运行);



     如果(光标!= NULL)
     {

         Log.e(跑,curosr不为空);
     而(cursor.moveToFirst())
     {

         Log.e(跑,curosr while循环输入);

         字符串临时=(cursor.getString(cursor.getColumnIndex(电子邮件)));
             串TEMP2 =(cursor.getString(cursor.getColumnIndex(名)));
        Log.e(跑,ID通过电子邮件将+温度+姓名+ TEMP2);

    }
 }
}
 

解决方案

您缺少selectionArgs两个

 公开光标查询(字符串表,字符串[]列,选择字符串,字符串[] selectionArgs两个,GROUPBY字符串,字符串有,字符串排序依据,字符串限制)
 

  

您可以包括哪些?S在选择,这将是由值替换   从selectionArgs两个,以使他们出现在选择。该   值将被绑定为字符串。

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

在你的情况将是:

 光标光标= myDataBase.query(EMP,新的String [] {电子邮件,名},NAME =?,新的String [] {辞典},NULL,NULL,NULL);
 

i want to get the row from databas which name = jiten but is gives error in syntax can anyone tell me what is the right syntax for getting the single row here is my code for database class

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

    }
 }
}

解决方案

You are missing the selectionArgs

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

You may include ?s in selection, which will be replaced by the values from selectionArgs, in order that they appear in the selection. The values will be bound as Strings.

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

in your case it would be:

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

这篇关于如何让单列带光标的Andr​​oid?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆