0

I built a table in the database, and now I want to access the all of the values in a certain column. Finally, I want to put the data into byte[]. Part of my code:

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();
}

2 Answers 2

3

Use this code

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

    do {
    int posi = result.getPosition();
     fstr[posi] =result.getString(0);                           
    }while (result.moveToNext());
Sign up to request clarification or add additional context in comments.

Comments

0

try this

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();

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.