Setting up sqlite database - java

Sorry I am a noob, I am trying to learn about sqlite databases using linux, I cannot find any tutorial that covers what I need from setup to creating to using. At the moment tutorials I find say open a shell using adb shell command but when I open a terminal this does not work even if I navigate to the android tools folder, I can get the sqlite command working but the tutorials dont explain how I use it. For instance, how do I store urls and map coordinates and how to I reference them.
I have tried to use the firefox plugin but I havent got a clue what it all means and every tutorial says sqlite database is easy but it seems so complicated.......HELP!!!!
P.S would it be possible to create the data within the application code, I have seen some apps that do this
Does anyone have a set up guide and tutorial that can help?

Take a look here: http://developer.android.com/guide/topics/data/data-storage.html#db
You should use a custom class extending SQLiteOpenHelper: http://developer.android.com/reference/android/database/sqlite/SQLiteOpenHelper.html
It gives you methods like onCreate, onOpen and onUpgrade which are very useful.

To set up your database :
The recommended method to create a new SQLite database is to create a subclass of SQLiteOpenHelper and override the onCreate() method, in which you can execute a SQLite command to create tables in the database.
To use it :
You can execute SQLite queries using the SQLiteDatabase query() methods, which accept various query parameters, such as the table to query, the projection, selection, columns, grouping, and others. For complex queries, such as those that require column aliases, you should use SQLiteQueryBuilder, which provides several convienent methods for building queries.
Resources :
developer.android.com - Data Storage

Are you using Java.
You can have a look http://www.zentus.com/sqlitejdbc/

Android has a class named SqliteOpenHelper using which you can create and communicate(do read / write operations) on sqlite using java. You can find many samples once you start searching in net. Here is one such sample.
http://www.reigndesign.com/blog/using-your-own-sqlite-database-in-android-applications/
If you want to open your database you can use Sqlite Manager which is available with Firefox as a Addon. It has a easy interface so that you can load your database directly and check .

If you are planning to create a new SQLite database then over ride and implement the onCreate() Method.
But if you are using a SQLite database that is created by another external source and you are going to pull it down, then leave the onCreate() method empty.

You might look at SQLite Manager, which is a free GUI and available in a Linux variety. I highly recommend it.

Related

Where to place my android app's data

I'm currently developing an app that lets you create and save excercises and routines for the gym. I want the app to come with some example excercises and routines and also to give the user the ability to add his own.
The thing is, I know I can use "getFilesDir()" and save it in the internal memory, but if I do that, how do I put my example files also in the internal memory? I don't think I can do that without creating those files by code everytime the app runs. I've also tried putting the example excercises in "res/raw" but then the ones the user adds go to a different place and I don`t know if that's good practice, apart from just how annoying it is having to read them from different places.
Where would be the best place to put those excercises and routines files?
Thank you very much!
The best practice is to store data inside "Sqlite Database".
"Sqlite Database" is the internal database that android provides to store data locally and is easy to use.
It's queries are easy to implement. It is more easy to work on, if you have worked on any database before. Just create a "Database Helper" class and initiate inside the activity where you plan to store data.
Many big applications like "whatsapp", use this database to store data on user's device.
The plus point of using "Sqlite" is that, you can iterate through each and every data easily.
It is quick, easy to work and is also a good programming practice. It is also secure.
While using a sqlite database for managing your app data is the traditional
approach, there are also alternatives to it. Realm is such an alternative. You can check the comparison with sqlite and see if it meets your need.
https://realm.io/
In Android development, you can store locally and as well as remotely. This link will walk you through all possible ways to store data.
As per your requirement, I would recommend you got for SQLite Database provided especially for android as it is light weight. Sqlite queries are straightforward and easy to use with some APIs comes with the package. you can start with this link with Sqlite.
I suggest using Firebase to store your data. Not only it is online and realtime, it can also work in offline mode and sync later. Because you're developing a gym app, why not give it an online or offline capability? I think users prefer it that way. You can check it at firebase.google.com

What's the best practice when populating a sqlite database with default data?

I'm making an app that will be using few hundred database posts from a sqlite database. I will not be adding new data during the lifetime of the app (unless I update the whole app).
I might end up using a static xml for the data, but I need to flag posts, so I guess a sqlite db would do the job best. I know how to implement it and I've released apps using sqlite before...
But my question is. How to I best populate the sqlite db the first time the app runs? Should I just bring in a file that I use as a resource and then copy to the apps space? What's the best/easiest practice?
The simplest solution is to use SQLiteAssetHelper. You basically drop your SQLite database into your project's assets/ directory, and use SQLiteAssetHelper in lieu of SQLiteOpenHelper. In addition to the sample code up on Jeff Gilfelt's GitHub repo for the library, I have a sample app demonstrating it as well.

How to create a SQLite database in a general java project (not specific to android) using Eclipse?

I want to create a database for my android app.
At first, I want create it fully and then I will use it on my android project.
I can make sqlite database in SQLite IDE (sqlite database browser).
But I want to create it programmatically.
Because I will fetch data from a text file and push it to database.
It will be very fast and easier than IDE to make a database.
So my question, is there any way to make a SQLite database without SQLite database IDE in general java project (not specific to android) and what is that?
Thanks in advance.
Sorry for my bad English.
You basically would just need to include the appropriate connection jars in your project and implement your own C.R.U.D. operations. A quick google search comes up with a a bunch of good tutorials. Here's a basic one to start with.
You should look at this project https://bitbucket.org/xerial/sqlite-jdbc. I've used it in several projects. very good.

How to store/access a local sql database on Android via Java

I am currently developing an Android app in Eclipse with Java. I need to store some data. I could use XML, or CSV, but I would prefer to have some sort of database locally that I can query to with sql. If there is some type of editing interface would also be good.
A good example would be Microsoft Access, but obviously that would not work on Android. You know, just somewhere simple where i can store data locally. Nothing complicated. Ease-of-development would be very useful.
Is there anything like that in the Android world?
Data in android are usually stored in SQLite database. Personally I use OrmLite - it's well documented and works like a charm...

sqlite database help

I have some questions regarding database in android.
In my project, I would like to create a database with single table. I would also like to insert data on this table from word or excel document. is it possible? if so please how can I do it? some code snippets would be of great help.
I have four different activities which I would like them to interact with this single table. the first is the main activity and its purpose is just to launch the other three activities according to user choice. so it has no interaction with the DB. but the other three activities will read from the table whenever called. Can you please tell me how to call the dbhelper on these activities? I am unable to do this and I am currently creating one db per each activity which is not the optimal way.
See the Notepad Tutorial on interacting with a database in Android, it is a complete sample application with explanations.

Categories

Resources