如何循环使用sqll表t

bpsygsoo  于 2021-08-01  发布在  Java
关注(0)|答案(1)|浏览(310)

这个问题在这里已经有答案了

android sqlite如何检查记录是否存在(14个答案)
10个月前关门了。
我如何查看我的数据库并找出数据库是否已经包含我试图解析到其中的数据
我的数据库:

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

代码:

  1. public boolean check_If_Data_In_DataBase(String albumName) {
  2. boolean bool = false;
  3. SQLiteDatabase db = this.getReadableDatabase();
  4. Cursor cursor = db.rawQuery("SELECT likeAlbum FROM " + Table_Name,null);
  5. while (cursor.moveToNext()){
  6. String name = cursor.getString(0);
  7. bool = name == albumName;
  8. }
  9. cursor.close();
  10. return bool;
  11. }
0sgqnhkj

0sgqnhkj1#

  1. Select count(*) as count from <table> where name = <albumname>

作为return,您将得到一个只有一行和一列的表,此字段显示表中有多少行符合where子句中的creteria,
因此,如果返回0,则数据不在表中;如果返回>=1,则数据不在表中

相关问题