Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/201.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql查询从android中的特定列和行检索特定数据?_Android_Sql_Sqlite - Fatal编程技术网

Sql查询从android中的特定列和行检索特定数据?

Sql查询从android中的特定列和行检索特定数据?,android,sql,sqlite,Android,Sql,Sqlite,我想获取数据库中链接到特定电子邮件的电话号码。我无法找到它的查询或如何查询 public String getContactNumber(String email){ SQLiteDatabase db = this.getReadableDatabase(); String query = "SELECT " + COLUMN_USER_MOBILE_NUMBER + " FROM " + TABLE_USER + " WHERE " + ema

我想获取数据库中链接到特定电子邮件的电话号码。我无法找到它的查询或如何查询

public String getContactNumber(String email){
            SQLiteDatabase db = this.getReadableDatabase();
            String query = "SELECT " + COLUMN_USER_MOBILE_NUMBER + " FROM " + TABLE_USER + " WHERE " + email +  " = " + COLUMN_USER_EMAIL;
            Cursor cursor = db.rawQuery(query,null);
            //What to put here to extract the data.

            String contact = cursor.getString(get); 
            cursor.close();
            return contact;
        }
提取数据。完全是个初学者试试这个

public List<String> getMyItemsD(String emailData) {
    List<String> stringList = new ArrayList<>();
    SQLiteDatabase db = this.getReadableDatabase();
    String selectQuery = "SELECT COLUMN_USER_MOBILE_NUMBER FROM " + USER_TABLE_NAME + " WHERE email= " + emailData;
    Cursor c = db.rawQuery(selectQuery, null);
    if (c != null) {
        c.moveToFirst();
        while (c.isAfterLast() == false) {
            String name = (c.getString(c.getColumnIndex("Item_Name")));

            stringList.add(name);
            c.moveToNext();
        }
    }
    return stringList;
}
public List getMyItemsD(字符串emailData){
List stringList=新建ArrayList();
SQLiteDatabase db=this.getReadableDatabase();
String selectQuery=“从“+USER\u TABLE\u NAME+”中选择列\u USER\u MOBILE\u NUMBER,其中email=“+emailData;
游标c=db.rawQuery(selectQuery,null);
如果(c!=null){
c、 moveToFirst();
while(c.isAfterLast()==false){
字符串名称=(c.getString(c.getColumnIndex(“项名称”));
stringList.add(名称);
c、 moveToNext();
}
}
返回字符串列表;
}

通过此方法,您可以轻松地通过任何其他方法获得该电子邮件的电话号码值

我建议如下:-

public String getContactNumber(String email){
    String contact = "NO CONTACT FOUND"; //<<<<<<<<<< Default in case no row is found.
    SQLiteDatabase db = this.getWritableDatabase(); //<<<<<<<<<< Generally getReadable gets a writable database 
    String[] columns_to_get = new String[]{COLUMN_USER_MOBILE_NUMBER};
    String whereclause = COLUMN_USER_EMAIL + "=?";
    String[] whereargs = new String[]{email};
    Cursor cursor = db.query(TABLE_USER,columns_to_get,whereclause,whereargs,null,null,null);
    //What to put here to extract the data.
    if (cursor.moveToFirst()) {
        contact = csr.getString(csr.getColumnIndex(COLUMN_USER_MOBILE_NUMBER));
    }
    cursor.close();
    return contact;
}
公共字符串getContactNumber(字符串电子邮件){

String contact=“未找到联系人”;//只需传递一些Android的SQLite教程。别偷懒,它不会花费太多时间,但会省去大部分问题。这会给出一个特定的值吗?我很困惑,因为它会提供存储在列表中的值,然后如何在另一个函数中传递这些值。1.检查SQLite数据库方法返回的游标是否为null Is没有用,它不会为null。2.遍历光标不需要如此复杂,您只需使用
而(c.moveToNext()){stringList.add(c.getString(c.getColumnIndex(“Item_Name”)))使用moveToNext的返回代码即可
.3.处理完游标后,您应该始终关闭它,因此在
返回stringList
之前,您应该有
c.close();
if(Cursor.moveToFirst()){contact=Cursor.getString(Cursor.getColumnIndex(COLUMN_USER_MOBILE_NUMBER))}
会更简单,因为大多数moveTo???方法在移动时返回true,而在无法移动时返回false。
public String getContactNumber(String email){
    String contact = "NO CONTACT FOUND"; //<<<<<<<<<< Default in case no row is found.
    SQLiteDatabase db = this.getWritableDatabase(); //<<<<<<<<<< Generally getReadable gets a writable database 
    String[] columns_to_get = new String[]{COLUMN_USER_MOBILE_NUMBER};
    String whereclause = COLUMN_USER_EMAIL + "=?";
    String[] whereargs = new String[]{email};
    Cursor cursor = db.query(TABLE_USER,columns_to_get,whereclause,whereargs,null,null,null);
    //What to put here to extract the data.
    if (cursor.moveToFirst()) {
        contact = csr.getString(csr.getColumnIndex(COLUMN_USER_MOBILE_NUMBER));
    }
    cursor.close();
    return contact;
}