How can i use Sqlite database in my android activity? - android

I am creating a sample application using sqlite database unfortunately I am not familiar in sqlite database concepts. I have the following requirements,
I have a sqlite database named as quotes.db. The database having two fields in is number and Quotes. Which is stored in assets folder.
In my Activity i have two fields one is edittext and another one is button.
When the user enter the value (number) in edittext and click the button. Now I display the corresponding quotes which is stored in database.
if any one having sample code snippet similar to this kindly post. Thanks in advance.

You can follow this tutorial which is an introduction to Android apps and especially to databases in Android.
Quting the website:
This tutorial on writing a notepad application gives you a "hands-on"
introduction to the Android framework and the tools you use to build
applications on it. Starting from a preconfigured project file, it
guides you through the process of developing a simple notepad
application and provides concrete examples of how to set up the
project, develop the application logic and user interface, and then
compile and run the application.

There are a couple of ways of creating and accessing a database in android.
Method 1: Use simple SQL statements
For that follow this tutorial: http://saigeethamn.blogspot.in/2009/10/android-developer-tutorial-part-12.html
Method 2: Use a class that extends SQLiteOpenHelper
For that follow this tutorial: http://www.reigndesign.com/blog/using-your-own-sqlite-database-in-android-applications/
I would recommend you to follow method 2 as that makes it much simpler to query and update your database once it is all set up. Also note that when you move on to 'Content Providers' method 2 will again be very very helpful.

The Android dev manual has a useful introduction to the process. Take a look at the Searchable Dictionary for some example code.
I gave an answer on this SO question for importing a database from a file in your assets/ directory.

Related

Using Existing sqlite Database with android ADT

I am developing an app in android which consists of activities that need to connect to the Database. I am having an existing sqlite DB with me. But I don't know how to include it in my project. This might be a very basic question, but as I am a newbie, I am finding it quite complex to get it working. Any help would be appreciated.
The easiest solution, by far, is to use SQLiteAssetHelper. You add one JAR to your project, package your database in a ZIP file in a specified location in your project's assets/ directory, then use SQLiteAssetHelper to access your database (much like you would use SQLiteOpenHelper).
try to read more about making a DatabaseHelper extension class
this really helped me during my first database driven app
http://www.codeproject.com/Articles/119293/Using-SQLite-Database-with-Android
The name of this feature of transfer database in android called database Ship.
I have already complete database shipUsing your own SQLite database in Android applications
Also you can see this Stackoverflow Answer

Making a database with android?

I'm working on an android project that requires writing to a created database and later reading from it.
The idea is for the user to fill out a form and then submit, it will submit into a database table in the first row. Then if they hit submit again it will submit to the second row.
I have all of the activity layouts defined but I'm confused on how to make the databases. I'm thinking maybe I can make a content provider?
Can anyone advise me on what to do? All of the questions I look at on here skip the baby steps, and that's what I need
Yes you should make a content provider. There are a lot of great tutorials out there for making databases - try section 8.0 of this one
http://www.vogella.com/articles/AndroidSQLite/article.html
Since you plan to use a pre-loaded (created) database wherein the DB structure has been already defined, Refer to this link on how to include your pre-created DB file into your app :
http://www.reigndesign.com/blog/using-your-own-sqlite-database-in-android-applications/
And to then add new data to your database refer to this tut.. You can ignore the create Table part here since you already have the table structure ready.
http://www.androidhive.info/2011/11/android-sqlite-database-tutorial/
Hope this helps.
First of all you dont need Content provider...Content provider is only need when you want to provide your data to other application...Its kind of central repository of data for other applications.
Now You have to use the SQLITE database in android...Since android support sqlite database..
Below link will guide you...
http://developer.android.com/training/basics/data-storage/databases.html
Google has large manuals for all the aspects of Android development http://developer.android.com/training/basics/data-storage/databases.html
it might be done without content providers too.
this might be helpful.
http://www.androidhive.info/2011/11/android-sqlite-database-tutorial/

Making a database helper class for a table with many fields

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.

android database issue

I am new to android.
I have an application where i am calculating the loan amount based on salary. For that I have a database of salary,Tax and medicare column. The tax and medicare depends upon the salary bracket. I want to know how to create the database and access it through the coding.
If any good sample code example is there please give the link.
Thanks in advance.
Here you can find a simple and straight forward tutorial from anddev.
Summarize from the tutorial:
Description: We'll need to to the
following things:
Create a DataBase (generally this is done just once)
Open the DataBase
Create a Table (generally this is done just once)
Insert some Datasets
Query for some Datasets
Close the Database
Android uses the SQLITE database Read up on it here: http://www.screaming-penguin.com/node/7742
I assume you have read the official Android developer guide. If not, there is a wealth of information about doing anything and everything you'd want on an Android device.
Since Android uses SQLite as it's internal database, I'd suggest reading documentation about it + the data storage part of Android guide.
These would be good starting points.
You may try this simple tutorial with nice graphics illustration.

What kind of database is used in Android document call functions?

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

Categories

Resources