1

我在我的 android 数据库中使用这个查询:

  public String getauthWithid() {
    String query = new String( "select login from table_inscri where ID = 1" );
    Cursor result = bdd.rawQuery( query, null );
    return result.toString();}

但是当我调用这个方法时它返回android.database.sqlite.SQliteCursor@

那么当 id=1 时如何选择列呢?

4

5 回答 5

2

编辑:正如格雷厄姆指出的那样,您将不得不关闭光标。所以使用下面的代码

result.moveToFirst();
String auth = result.getString(result.getColumnIndex(COLUMN_NAME));
result.close();
return auth;
于 2012-08-15T12:34:18.670 回答
1

这是正确的做法。以防出错。

public String getauthWithid() {
   String query = new String( "select login from table_inscri where ID = 1" );
   Cursor result = bdd.rawQuery( query, null );

   String returnString = ""; // Your default if none is found

  if(result.moveToFirst())
  {
    returnString = result.getString(result.getColumnIndex("login"));
  }
  result.close();

  return returnString;
}
于 2012-08-16T12:01:14.357 回答
0

使用它应该从数据集的列中获取数据。

if (result != false) 
{
    result.moveToFirst(); // moves the cursor to the first record        
    do 
    {
        result.getString(0); // gets the data in that record
        // process string here 
        // - such as add to an arrayList and then return the list after the loop
    } 
    while (result.moveToNext()); 
    // return list here
}
于 2012-08-15T12:37:03.213 回答
-1
Cursor cursor = db.rawQuery("select login from table_inscri where ID='" + 1
            + "'", null);
于 2012-08-15T12:29:28.607 回答
-2

只需进入您的 sqlite shell:

$ sqlite3 path/to/db.sqlite3

一旦进去,只需点击 sqlite> .schema

你会得到一切。

于 2012-08-15T12:30:35.423 回答