我在我的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时如何选择列?
答案 0 :(得分:2)
编辑: 正如格雷厄姆指出的那样,你将不得不关闭光标。所以使用下面的代码
result.moveToFirst();
String auth = result.getString(result.getColumnIndex(COLUMN_NAME));
result.close();
return auth;
答案 1 :(得分: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;
}
答案 2 :(得分: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
}
答案 3 :(得分:-1)
Cursor cursor = db.rawQuery("select login from table_inscri where ID='" + 1
+ "'", null);
答案 4 :(得分:-2)
进入你的sqlite shell:
$ sqlite3 path/to/db.sqlite3
一旦进入,只需点击sqlite> .schema
你会得到一切。