Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/206.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sqlite/3.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
Android:在sqlite中搜索三列_Android_Sqlite - Fatal编程技术网

Android:在sqlite中搜索三列

Android:在sqlite中搜索三列,android,sqlite,Android,Sqlite,Im编写一个应用程序,记录所有连接单元的单元塔ID,并将值写入数据库 ID列\操作\ ID LAC CID xxxxx xxxxx XXXXXX 我的代码: public String findProduct(String lacId) { String query = "Select * FROM " + TABLE_TOWERS + " WHERE " + COLUMN_LAC + " = \"" + lacId + "\""; SQLiteDatab

Im编写一个应用程序,记录所有连接单元的单元塔ID,并将值写入数据库

ID列\操作\ ID LAC CID

xxxxx xxxxx XXXXXX

我的代码:

  public String findProduct(String lacId) {
        String query = "Select * FROM " + TABLE_TOWERS + " WHERE " + COLUMN_LAC + " =  \"" + lacId + "\"";

        SQLiteDatabase db = this.getWritableDatabase();

        Cursor cursor = db.rawQuery(query, null);

        String lac = null;

        if (cursor.moveToFirst()) {
            cursor.moveToFirst();
            lac =cursor.getString(2);
            cursor.close();
        } else {
            lac = null;
        }
            db.close();
        return lac;
    }    
但是,通过这段代码,我得到了包含这个编号的所有行。我想实现一个函数来搜索Op_Id、lac和cid的所有三列,以缩小搜索范围并进一步缩小搜索范围。但是,我无法搜索所有三列以缩小搜索范围

例如

如何设计这样的函数? 谢谢,萨希尔解决了

 public String findID(String lacId, String opId, String cid) {
        String query = "Select * FROM " + TABLE_TOWERS + " WHERE " + COLUMN_LAC + " = \"" + lacId + "\" AND " + COLUMN_OPERATOR_ID + " = \"" + opId + "\" AND " + COLUMN_CID + " = \"" + cid + "\"";

        System.out.println(query);
        SQLiteDatabase db = this.getWritableDatabase();

        Cursor cursor = db.rawQuery(query, null);

        String id= null;

        if (cursor.moveToFirst()) {
            cursor.moveToFirst();
            lac =cursor.getString(0);
            cursor.close();
        } else {
            id = null;
        }
            db.close();
        return id;
    }

…你的问题是?在where子句中可以有很多条件。CID=CID和LAC=LAC,以此类推。
 public String findID(String lacId, String opId, String cid) {
        String query = "Select * FROM " + TABLE_TOWERS + " WHERE " + COLUMN_LAC + " = \"" + lacId + "\" AND " + COLUMN_OPERATOR_ID + " = \"" + opId + "\" AND " + COLUMN_CID + " = \"" + cid + "\"";

        System.out.println(query);
        SQLiteDatabase db = this.getWritableDatabase();

        Cursor cursor = db.rawQuery(query, null);

        String id= null;

        if (cursor.moveToFirst()) {
            cursor.moveToFirst();
            lac =cursor.getString(0);
            cursor.close();
        } else {
            id = null;
        }
            db.close();
        return id;
    }