开发者

How to read sqlite file using cursor and display data in a listview

开发者 https://www.devze.com 2023-01-16 05:38 出处:网络
Hi im trying to read sqlite file which is placed in asse开发者_运维技巧ts/databases folder i followed this link to read data from sqlite file

Hi im trying to read sqlite file which is placed in asse开发者_运维技巧ts/databases folder

i followed this link to read data from sqlite file http://www.reigndesign.com/blog/using-your-own-sqlite-database-in-android-applications/

im getting error

no such table : while compiling SELECT _id, name, address FROM stores

Is there any permission i need to write in manifest to read sqlite file data?

Please let me know how i can solve this issue. Or else please give me any reference link to follow.

Thanks in advance


The way you'd want to do this is to make a new DBManager object that creates the database in its onCreate method--that way when the DatabaseHelper is first instantiated, the table will be created for you. Then you'd instantiate one and call getReadableDatabase() on it to get a DB object which you can then query.

This tutorial may help you more, it's more succinct and up to date: http://developer.android.com/guide/topics/data/data-storage.html#db

After that, to set up the list view in a ListActivity, you can call setListAdapter and pass in a SimpleCursorAdapter. Here's a tutorial on that: http://developer.android.com/guide/appendix/faq/commontasks.html#binding


Check if database already exists or not. If you are running on emulator.

write following on terminal/shell:

adb shell cd data/data/your package name(ex. com.android.etc) ls if there exists databases directory then may be database is created

cd databases ls

it will show your database if exists;

sqlite3 "your db name"

then write

.tables

it will show the name of table if exist:

now write your query over here to check for errors for ex:

sqlite> SELECT _id, name, address FROM stores

hope it helps..... and yes there are no as such required permissions for this.

0

精彩评论

暂无评论...
验证码 换一张
取 消