Using android with existing SQLite [duplicate] - android

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
How to ship an Android application with a database?
I'm trying to develop an app that needs to read data from a database and display it to the user. Perhaps in the future I could add an option for users to leave comments on various articles, for which I'll need a server instead of SQLite right?
But for reading data is it better to have a local database with 3k to 5k records in each table?
Secondly I'm a total newbie when it comes to Android and databases. I've dealt with PHP+MySQL but it's not quite the same. Since the records are a lot, I'd like to enter them from a back-end (sqlitebrowser) and copy the file from assets folder (done this already). I've tried creating a database helper class using tutorials online but that didn't work at all for me. I also tried creating a connection profile in Eclipse which kinda works when I tried using the SQL Scrapbook view. It doesn't give errors, but select query doesn't show anything in SQL Results
Remember I do not want to create a new database, just copy the existing one from Assets to data/data/my.package/databases/ and read from there.

The Android implementation of SQLite requires two conventions for the data base file. If you don't follow these conventions, Android's SQLite library won't read the data base correctly.
Every table must have an INTEGER PRIMARY KEY field named _id. (This may just be standard SQLite stuff.)
The data base must have a table named android_metadata. This table must have a TEXT column named locale and it should have one row with the locale name for the data. The value "en_US" works for me. Schema:
        CREATE TABLE android_metadata (locale TEXT)
Make sure that the data base in your assets conforms to these conventions.

The following site provides all your needs.Using your own SQLite database in Android applications

Related

How to store and use existing information (in Excel) in my app with SQLite?

So I have a big Excel spreadsheet with multiple columns and rows that I'd like to somehow use in my app to look up certain information. How would I go about converting this spreadsheet to an SQLite DB -> table?
I'm aware of this website (http://converttosqlite.com/) but for some reason when I try to use the database it produces in my app, there are no tables inside the database except android_metadata.
TL;DR what's the most common way of converting and using a bunch of data (initially stored in an Excel spreadsheet) in an Android application?
The database produced by the conversion will not work because the Sqlite used in Android looks for a special table in the database order to read it. You can read more about this here.
A couple of options to add the data are:
To modify the converted database (as described in the link above) so that it can be opened and read by the Android Sqlite functions
To export the Excel data to a CSV file, then parse and insert that data into a new database from within your App.

How can I save many sentences efficiently in Android?

I am developing an app for Android which will have many sentences organized with categories. Besides, this app must upgrade the sentences with a mysql database.
My question is: How can I save many sentences efficiently?
I have thought creating a sqlite database in my pc and add it to the app project. Is that possible?
Maybe, could I do another thing?
Like you said; create your database using sqlite on desktop and then include it in your application in the \assets folder. Use it normally in your application.
Remember to always us _id as the primary key in your tables.
For more details check this blog post

How to store a large number of words (to be accessed by an android app)?

I have a list of words (112,000 in alphabetical order) with one word definitions. The definitions are sometimes more than one and are in the format:
word:definition1|definition2|...
The max number of definitions for a word is 8.
I need a method to store these in a file (or more is okay) so they can be accessed by an android app. Only one word will be accessed at a time. This list will never change.
Considering SQLite, how would I insert the large data into a database?
Considering RandomAccessFile, how would I create a index for these words?
Is there another way?
Thanks.
I would suggest you to go with SQLite as it would be easy to fetch data as and when required and it would be simply easy to get/date/update data from particular position too.
One more benefit is that you can prepare SQLite database by using GUI tool too.
Now follow below procedure to use Existing SQLite database, means that you will have database ready with words data:
Prepare SQLite database same as we do in .NET , here you can prepare it using one of the best tool SQLite Manager which you can download it as a tool/add-on inside Mozilla Firefox.
Once you are done with database, simple paste it inside assets folder.
Now write a code to copy database from assets folder into our app. There are plenty of examples available on web for the same.
Use a sqlite DB , storing 112,000 or more shouldn't be a problem at all for sqlite .
Your can use your db schema something like the following :
And there can be multiple entries of wordId -> meaningId , for each word .
for pre-storing data you could use a tutorial provided by me in my blog : Using Pre-populated sqlite database in android

PreLoaded data in SQLite for android [duplicate]

This question already has answers here:
Ship an application with a database
(15 answers)
Closed 8 years ago.
I'm new to android application development. I'm on course of developing my first app which displays the time table of the selected class/faculty on the selected day(Mon,Tue etc.,).
I'm all done with UI. Now my problem is how & where to write the code for the entire database insertion (as it should be loaded from the beginning).
Can any one help me with this in a detailed manner as i'm new to this field ?
The general steps for what you are looking to do are as follows:
1) Create/convert your database to SQLite (the db used by Android)
2) Put the database in your assests folder
3) Write code to copy the DB from your assets folder to the private databases folder for your app when it runs for the first time.
4) Write code to access the database as necessary once the DB is in the private folder.
A tutorial for using/importing an existing SQLite database in your app can be found at http://www.reigndesign.com/blog/using-your-own-sqlite-database-in-android-applications/
There are many tutorials for creating a database helper class (to handle Creation, Reading, Updating and Deleting functions). A good one I've used and recommended before can be found at http://www.anotherandroidblog.com/2010/08/04/android-database-tutorial/
I think what you need is to ship your database with your apk. You, however, will need to move the database file, because the system expects its databases to be in the private storage. You can see how this is done here.
If it so happens that your database file is big (more than 1MB) combine with this answer in order to achieve the shipment.

How to port an existing MS Access to SQLite for use with android app developement? [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
How to convert MDB to SQLite in Android
I have an MS access database with few tables and quite a bit of data in it. I was wondering if it is possible for me to port all those tables over to sqlite for an android app that I am developing.
Thanks for your time
The easiest way would be to export each table to CSV and then use an SQLite tool of some sort to import those tables into your SQLite database. I use SQLite Expert.
Then you would need to make some modifications to that database and those tables to make it usable by Android to populate listviews and other widgets.
1) The database must contain a table called "android_metadata"
2) This table must have the column "locale"
3) There should be a single record in the table with a value of "en_US"
4) The primary key for every table needs to be called "_id" (this is so Android will know where to bind the id field of your tables)
Then you put the DB in your assets folder and when your app starts copy it to your apps data directory.
A good link for this copying process is here.
You could also use SQLiteAssetHelper to handle the transfer of the DB from assets to your data directory instead of doing the way the tutorial shows if you felt the need.

Categories

Resources