sqlite database help - java

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.

Related

Saving Things to local storage in java/javafx?

I don't know if this is a super noob question, but I'm currently building an app from scratch with the knowledge i've gained so far, and I'm making a "Notes" app where You can create notes, delete, edit(update), etc etc.
The question I'm having is that I know I can use a database to store data from my input, and I know i can use A Database to save, open the data, but Just incase, does Java have a LocalStorage, like JavaScript/JSON where you can save things and open them up later?
If there is LocalStorage for applications to save data, and open it up after running again, what would be some good resources to read about it and learn it so I may integrate it into my application?
If there is no localstorage, I wan't to be able to perhaps allow the user to add images when creating notes, how would I be able to do that using a database?
As far that I know of there packages that allow you to store data as you intend, but following on your next question, you could possibly store the address/file name of the image you wants to add to the database. You could then use it to retrieve the image file and display it.
If you have any questions on image implementing images in java, reference this documentation and tutorial
If you have any more questions on working with databases, reference this documentation
I hope this helps.

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 grab data from the online database?

By any chance, is there anyone who can help me? As currently I am doing my major project, and also a beginner in android and java. I am doing the login function for my project. I took
reference from here. However, one problem that I am facing now is I do not know how to grab the details (name and email column) from the database and display out these two information. Is there any guide on how to grab the information and display it out after the user have log in? Thank you very much.
1. Try using SQLite DataBase, which ships with Android.
2. Its simply a file with NO DATABASE SERVER.
3. This DB can be as small in size as 250KB.
For a quick and easy example see here:
http://android-er.blogspot.in/2011/06/simple-example-using-androids-sqlite_02.html
For understanding the queries look here:
http://mobile.tutsplus.com/tutorials/android/android-sqlite/
http://www.vogella.com/articles/AndroidSQLite/article.html

Setting up sqlite database

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.

Categories

Resources