如何使用android中sqlite表的行id从特定列中检索单个数据?

时间:2016-12-03 14:34:28

标签: android sqlite android-sqlite

sqlite表中有几列。我想使用行ID检索特定数据。例如:我想要列“name”的数据,其行号为“1”。我怎么能在android中做到这一点?

1 个答案:

答案 0 :(得分:0)

我的代码示例:

private static String t(String i, String table) {
        SQLiteDatabase db = ODB.getInstance().openDatabase();
        String lng = hl;
        String Sid = "Sid___";
        String sql = "SELECT " + lng + "  FROM " + table  + " WHERE " + Sid + " = '" +  i + "'";
        Cursor cur = db.rawQuery(sql, null);
        String out = "";
         if (cur.moveToFirst()) {
             do {
                 out =(cur.getString(0);
                } while (cur.moveToNext());
              }else{
                  throw new NullPointerException();
              }
         cur.close();
         ODB.getInstance().closeDatabase();
         return out;
    }