简体   繁体   English

在SQLite DB表中搜索数据

[英]Searching for data in SQLite DB table

I have a text view in which user enters a string. 我有一个文本视图,用户可以在其中输入字符串。 I need to search for that string in a table and return a boolean value if a string matches. 我需要在表中搜索该字符串,如果字符串匹配,则返回一个布尔值。

I am not into SQL, so can anyone please help me figure out how to do it. 我不喜欢SQL,所以任何人都可以帮助我弄清楚如何做。

Assuming that you know the basics & the object db of type SQLiteDatabase exists in your DataAccessLayer, below is the function which returns true false based on whether the location exists or not? 假设您知道DataAccessLayer中存在SQLiteDatabase类型的基础知识和对象db,下面是根据位置是否存在返回true false的函数?

public boolean IsRecordExists(long empid) throws SQLException
{
     String where = "empid =" + empid;
     Cursor mCursor = db.query(true, "employeeinfo", new String[] {"empid"}, where, null,null, null, null, null);

      if (mCursor != null) 
      {
           if(mCursor.moveToFirst())
                return true;
          else
                return false;
       }
    return false;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM