0

我在数据库中建立了一个表,现在我想访问某个列中的所有值。最后,我想将数据放入byte[]. 我的部分代码:

db.execSQL("create table thing(id integer primary key" +
            " autoincrement, name varchar(20))");

List<Integer> all = new ArrayList<Integer>();       
String sql = " SELECT id from " + DB_NAME;
Cursor result = this.db.rawQuery(sql, null);

for (result.moveToFirst(); result.isAfterLast(); result.moveToNext()) {
    all.add(result.getInt(0));          
}

String[] fstr = (String[]) all.toArray();
for (String bstr : fstr) {
    byte[] bbs = bstr.getBytes();
}
4

2 回答 2

3

使用此代码

String[] fstr = new String[result.getCount()] ; 

    do {
    int posi = result.getPosition();
     fstr[posi] =result.getString(0);                           
    }while (result.moveToNext());
于 2013-03-23T04:28:56.877 回答
0

尝试这个

Cursor c=this.db.rawQuery(sql, null);
if(c.getCount()>0)
{
   for(c.moveToFirst();!c.isAfterLast();c.moveToNext())
   {
     String str=c.getInt(0));// or c.getString();
   }
}

else
{
  Log.d(" Null value in cursor ", " null ");
}
c.close();
dbhelper.close();
于 2013-03-23T04:59:26.463 回答