I am working on my graduation project
It has the same idea as calories counter application of Fatsecret >> if you know!
I created the database file using SQLite, I copied it into the asset folder, and then wrote the code as in this link:
http://www.reigndesign.com/blog/using-your-own-sqlite-database-in-android-applications/
recently I read a code that only use openOrCreateDatabase(name, mode, factory) to deal with the database
Can I use this in my case, which code is better?
Best Regards
There is good basic documentation on how to work with sqllite in android. Check out http://developer.android.com/guide/topics/data/data-storage.html#db to get an overview on how to use sqllite in your application.
Basic idea is to extend http://developer.android.com/reference/android/database/sqlite/SQLiteOpenHelper.html class and from there do the rest of CRUD operations on your database.
Also i forgot to mention: preferably avoid using openorcreatedatabase method, recommendation is to keep using sqliteopenhelper instead
Related
I have created a database in SQLiteStudio. The database consists of a single table, with columns 'Name', 'Age' and 'Occupation', and several rows of data.
I want to transfer that database from SQLiteStudio to an Android phone. How would I do this?
Well, the simplest way if there are only a few rows would probably be to create the schema and populate it in SQLiteOpenHelper.onCreate(db) using SQL statements executed with db.execSQL().
If you would like to avoid that however, and just directly take the database that you've created externally over into your app, you could look into Android SQLiteAssetHelper
Yes, the Android SQLiteAssetHelper is really simple compared to other guides that uses hundred of lines with codes. Tried numerous guide and tutorials before I found out about that helper. Here is a really simple guide to follow where he's using it and explains it pretty good.
Import and use external database in Android
i am new to android. i already created a database and store some data there. What i want is that the stored data in my database, I want to print it all out in another activity.
I don't know how to do this sharing of one database in all activities. I did research but they are all complex codes that i don't understand. Greatly appreciated if you could give me some simple codes about it. Thanks
im using SQLLite database.
You can use the same database throughout the whole app. In order to create an interaction bridge between your Activity and Database, you need to utilise few classes like ContentResolver and ContentProvider. Here is android example of how to create a ContentProvider -
Creating ContentProvider
You can also read this blog for better understanding about how things work in Android in terms of Database.
Hope it helps.
The same database can be used in all activities.You need to create a class through which you can access the database.Before I can tell you how to retrieve data you need to tell me somethings.You have written that you have already created a database.Have you created an external database and are trying use the database from assets folder or have you created an internal database in your android application?
I'm currently trying to learn how to use a SQLite database with android. I've managed to successfully follow http://www.androidhive.info/2011/11/android-sqlite-database-tutorial/ but I'm now looking to make a table with 25-30 fields. It seems like it would be a huge task to type out all this in a similar style to that link especially as I'd want to be able to search by many of those fields.
Is there something I can use to automatically generate a database helper class with this number of fields and methods to search them? Or am I going about this completely the wrong way?
Thanks
First off i just recently started android programming also and i particularly enjoyed this tutorial about databases : http://www.vogella.de/articles/AndroidSQLite/article.html
To generate the queries i think it will be better you use an SQLite Database Manager and just copy and past your queries in the methods.
I have been trying to open my ready made sqlite data base
in my android application my question is:
how do I open an sqlite database with the function:
openOrCreateDatabase();
And where should i put the sqlite file
And if my approach is wrong please enlighten me
Best way to work with SQLLite on Android is having a class which extend SQLiteOpenHelper. Here is good end-end example on how to work with SQLLite on Android. http://www.screaming-penguin.com/node/7742
I would recommend using a SQLiteOpenHelper. You can extend it to create your own helper class.
Okay, so I am still learning to do some coding here, and I seem to have gotten stuck.
I want to have a select number of documents added to a package for the Android OS
but I don't know how to store said documents. Do I add them all under res/raw, or make an SQLite database and call from there?
More importantly, I need to be able to call those documents when a search criteria is added.
I was on the Android reference site, and they add write functions for the SQLite db, which I would prefer not having as an option.
What kind of database should I implement here?
I would prefer a link to an example, but anything would help at this point.
Try reading this.
Notepad example
or make an SQLlite database and call from there?
No you don't create a SQLlite database it will be created for you after your App start the database call.
See this SQLiteOpenHelper
And SQLiteDatabase