【问题标题】:How to loop through SQlL table t [duplicate]如何通过 SQl 表循环到 [重复]
【发布时间】:2020-10-21 04:09:23
【问题描述】:

我如何查看我的数据库并找出数据库是否已经包含我试图解析到其中的数据

我的数据库:

public void onCreate(SQLiteDatabase db) {
        db.execSQL("CREATE TABLE UserInfo(ID INTEGER PRIMARY KEY AUTOINCREMENT, Users_Name TEXT, PlaylistName TEXT,likeAlbum TEXT)");
    }

代码:

public boolean check_If_Data_In_DataBase(String albumName) {
        boolean bool = false;
        SQLiteDatabase db = this.getReadableDatabase();
        Cursor cursor  = db.rawQuery("SELECT likeAlbum FROM " + Table_Name,null);
        while (cursor.moveToNext()){
            String name = cursor.getString(0);
            bool = name == albumName;
        }
        cursor.close();
        return bool;
    }

【问题讨论】:

标签: java mysql sql sqlite android-studio


【解决方案1】:
Select count(*) as count from <table> where name = <albumname>

作为回报,您会得到一个只有一行和一列的表格,该字段显示您的表格中有多少行满足 where 子句中的条件,

所以如果它返回 0 则数据不在表中 如果它返回 >=1 它是

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-03-10
    • 2018-12-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-03-21
    相关资源
    最近更新 更多