Android记录在数据库中存在()?

Android记录在数据库中存在()?,第1张

Android记录在数据库中存在()?

考虑那

mDb
是你的
SqlLiteDatabase

public boolean Exists(String _id) {   Cursor cursor = mDb.rawQuery("select 1 from yourTable where _id=%s",         new String[] { _id });   boolean exists = (cursor.getCount() > 0);   cursor.close();   return exists;}
  • 我将您的参数保留
    _id
    为a,
    String
    但我认为应该将其作为
    Long
  • select 1
    它比
    select columnName
    因为不需要在select子句中从表中检索所有值而更快。
  • 您可以将字符串
    select 1 from...
    放入静态最终常量中,以使其更快。


欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/zaji/5429101.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-12-11
下一篇2022-12-11

发表评论

登录后才能评论

评论列表(0条)

    保存