views:

197

answers:

1

So I've recently completed this tutorial and it works great, but I'm a little stuck on reading the data from my database.

I'm now reading from the database file thanks to Orsol by using this tutorial but I'm looking now for a method I can call which will return me the values of a given field. Or at least a method that let's me execute SQL.

The closest I have is by calling this:

public List<String> SelectAll()
{
    List<String> list = new ArrayList<String>();
    Cursor cursor = myDataBase.rawQuery("SELECT * FROM androidtable", null);

    if (cursor.moveToFirst())
    {
        do
        {
        list.add(cursor.getString(0)); 
        }
        while (cursor.moveToNext());
    }

    if (cursor != null && !cursor.isClosed())
    {
        cursor.close();
    }
    return list;
}

But this just throws a SQLiteException:

android.database.sqlite.SQLiteException: no such table: androidtable: , while compiling: SELECT * FROM androidtable

I do however know that I am loading the correct file (which does have this table), as if I change the directory path or database name, it will fire a run time error.

Can anyone help?

Thanks

+1  A: 

If you want to use database created outside of your application, follow this tutorial

Orsol
OK, I've got this running now. However there are no selection methods available on that site. Do you have one I could use?
ing0
What do you mean under "selection methods"?
Orsol
This tutorial reads in the database, but how to I get any data from it? By selection method, I mean to call SQL.
ing0
You have SQLiteDatabase myDataBase member there, so you can call myDataBase.rawQuery("select * from tableName", null) and use cursor to iterate through result set.
Orsol
Thanks yea, I had just found that before you posted. My last error was strange. The device thought the db existed when it didn't. I deleted the app and rebuilt and all is well. Thanks for your help though!
ing0