I am a novice, and am creating a simple app that just reads data from a table in an SQLite database and displays on the GUI. (Just select operation )
During development, I created the database and the table from the tool "SQLite Database browser". And I inserted all data into the table through the tool.
Now, my doubt is ..
1) In java code, should I have some method that creates database and table ?? (For now, I have methods to do the select operation alone)
2) The database I created is located in my local drive. When the apk file gets created would the database also be included in the apk file ??
Pls help !! Thanks in advance !!
1) In Java code, should I have some method that creates database and table ?? (For now, I have methods to do the select operation alone)
No, You have to just copy your database file from /asset directory to /data/data/<package_name>/database directory. And only use select operation alone. You don't need to use create Database and table operation..
2) The database I created is located in my local drive. When the apk file gets created would the database also be included in the apk file?
For this, as I mentioned above you have to first put your database file into application's /asset directory, then copy it to internal storage (when your application start), then it works.
Look at this SO question How to ship an Android application with a database?. It answered what you needed.
try below link
http://www.higherpass.com/Android/Tutorials/Accessing-Data-With-Android-Cursors/
Related
I am building an Android application that fetches data from a cloud database and stores it in SQLite locally so that user does not need to fetch it again and again.
Now I need to find an efficient way to predefine a few rows in the SQLite database and provide it along with the APK. Is this possible? if so, how do I achieve it?
Yes it is possible.
You follow these steps :-
You create the database externally, populating it, and copy the file to your App's assets folder.
You may have to create the folder.
If using Android SQLiteAssetHelper then you will need to create a databases folder in the assets folder.
There are various tools for Creating and Managing SQLite Databases. e.g. Db Browser for SQLite.
You then need to modify your App to copy the file from the assets folder (or assets/databases folder) and then open the database. Noting that you only do the copy if the database doesn't already exist.
Using the Android SQLiteAssetHelper simplifies this process.
Say I have data about customers and I initially have around 1000 pre-determined customers details I want to insert into my SQLiteDatabase.
Would it be wise to store that data into a text file in my assets folder with my own formatting (tabs to indicate columns and new lines to indicate rows), then just read the text file and insert the data into the database with insert statements? I feel this is not the best way and very in-efficient.
Is there a better way of doing this?
You can use the utility to create your SQL Lite database offline on PC, such as this:
http://portableapps.com/apps/development/sqlite_database_browser_portable
You can package this database along with your app and then put it on phone storage and continue from there.
You can do do in two ways..
Way 1:
You can make one .sqlite file with already 1000 customer records inserted in database and you can use it that .sqlite file from assets folder. Then you can copy those records in your internal database or use that only database.
Way 2:
You can put this 1000 records on server and call it by web service at first time app is launched..
Hope it will help you.
User a .sqlite or .db file in your assets folder with prelaoded entries and import this file to you app from asset folder.
You can use this add-on to access and create you db file
https://addons.mozilla.org/en-US/firefox/addon/sqlite-manager/
and this is tutorial to access database file from assets
Android: Accessing assets folder sqlite database file with .sqlite extension
I would bring along the already pre-populated database .db file.
I've done this before with "sample" data included as part of an application.
The application that I am creating will have a database that will have questions and answers. My problem is that I will be required to make hundreds of inserts to make the database complete. What is the best way to make it possible to do hundreds of insert statements. I am also thinking about to creating the database through the SQlite manager and from it to export a .sql file and use it to create a DB for my application.
If you have static data inside your database the it would be better to create the database from SQLite Manager and keep it inside assets folder and then copy it from assets folder into your databases directory when your Application starts. Also check the database file if exists the don't copy else it will overwrite the previous file everytime when you start Application.
i have to create a DIRECTORY in a database in which a few file will store.when user need any kind of file, the file fetches from that directory .
You can't cerate a directory in an sqlite database.
Either you create a directory on the filesystem using File.mkdir.
Or you create a table in a sqlite database. Here's a good tutorial.
There is no way to make directories in sqlite db.
Use android provided api for data storage read this tutorial.
Please first read about databases & then try to use it!!
Database:
A database is an organized collection of data, today typically in digital form.
Directory:
A directory or folder is nothing more than a location on a disk used for storing information about files.
I'm writing my first serious Android App, which basically is interface to three DB tables.
Data in those tables are predefined by me, so, user should install those app with those data.
What is the best way to include those data in application package? Maybe there is a way to embed SQLite into my application distribution?
Or is the only way is to define array of "insert into" strings somewhere in class and execute them to fill internal SQLite storage?
Would appreciate any recommendations.
I am currently doing the same thing in my app. Having a sqlite database file in my assets folder and copying it into the SD card at startup if it's not in there. There's a nice tutorial there and I use part of its code.
Put the database file in your assets and then copy it over to your application's data directory.
Your can check out this tutorial