How to access sqlite database which already exists in android - android

I have created an sqlite databse and put it into the assets folder. How can I access it? I have created a database helper class also, but my data is "not taking the path".
Plz help me
Thanks

Copy your database file from /asset to internal databases directory /data/data/<package_name>/databases/, then use that database file.
Look at this SO question How to ship an Android application with a database?.
Also this tutorial Using your own SQLite database in Android applications

Related

Backup SQLite database and restore it back when the Android application is installed

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.

How to provide the security to my .sqlite file in assets folder?

In my app i have use .sqlite database when zip my .apk file and extract this one my all code and database file also is came.How to provide the security to my database file and source code any one please give any suggestion.
Thank u in advice.
So at a guess you are using a pre-populated SQLite database? You could use SQLCipher to encrypt the database - it works with pre-populated and new ones created by the app.

How to specify the location of SQlite database android?

When I create an SQlite Database I dont find it in resources of my android project so I want to locolize it in my hard disk , and how to proceed to open it ?
You can't directly save your database into harddisk But you can create database in sdcard
then copy that database from sdcard to your harddisk.
Then you can access that database using SQLite Database browser
You have to do some selection from your database to see all records
here is a tutorial that can help you

how to CREATE DIRECTORY in android sqlite database?

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.

Should I explicitly create SQLite tables in my app?

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/

Categories

Resources