0

我必须使用他们的 id 从数据库中检索一个字符串。我完成了检索,但它以某种对象格式返回,而不是作为字符串。请帮助我..

我的检索地点:

db.open();
     for(int i=1;i<=5;i++)
     {       
     if(i==1)
         group1=db.getspintitle(1);
     if(i==2)
         group1=db.getspintitle(2);
     if(i==3)
         group1=db.getspintitle(3);
     if(i==4)
         group1=db.getspintitle(4);
     if(i==5)
         group1=db.getspintitle(5);     
     }

db.getspintitle() 方法:

public String getspintitle(int rowId)throws SQLException
{

    String sumtotal="";
    Cursor cursor1 = db.rawQuery(
             "SELECT spin from spinner WHERE _id='rowId'", null);  
     sumtotal=cursor1.toString();   
     cursor1.close();       
     return sumtotal;   
}
4

2 回答 2

0

供您参考,下面将返回您Cursor,而不是简单的字符串。

Cursor cursor1 = db.rawQuery("SELECT spin from spinner WHERE _id='rowId'", null); 

要从游标中检索值,您必须遍历游标。

现在,在您的情况下,您可以执行以下操作:

 Cursor cursor1 = db.rawQuery("SELECT spin from spinner WHERE _id='rowId'", null);  

     if (cursor != null && cursor.getCount() > 0) {
         cursor.moveToNext();
         sumtotal= cursor.getString(0);
         cursor.close();
     }
于 2012-07-18T07:04:13.267 回答
0
  String[] sumTotal= new String[cursor.getCount()]
   while(cursor.moveToNext())
         sumtotal[i] = cursor.getString(0);
于 2012-07-18T07:07:59.660 回答