Android Studio (Database From Asset Folder) - java

I followed this tutorial. Link-
I successfully implemented what's in the tutorial.
After that I Use Update command to update my DB from the asset folder.
In my device i can see The updated part,
But when i Import the DB File to SQL DB Browser, the DB File remains unchanged.
I need the DB File for other use so im using Android to fill the datas what i need. Thanks.

If you want to ship your Android app with a populated DB, then you should definitely use the sqlite-asset-helper by Jeff Gilfelt. You can find a real example of how to use the library here: http://www.6020peaks.com/2015/03/how-to-ship-an-android-app-with-preloaded-data/
Update: I just saw that the tutorial you followed is also using sqlite-asset-helper. If I understood your question correctly, I think you are looking at the wrong db file. The file that you need and that will contain all the new data generated by your android app will be here: /data/data/application_package_name/databases.
Check this out for more info on that direction: What is the default database location of an android app for an unrooted device?? Is it same as for rooted one?

Related

Android Room database created 3 files including -shm and -wal files

I have created a database using Room database library with name ImageDatabase, when I opened my Device File explorer in Android studio inside the database folder there were three files with names ImageDatabase, ImageDatabase-shm and ImageDatabase-wal. I wanted to know what are these files meant for? Any help would be great
Thanx All
The data in your database is contained in all three. The one with no extension is the main database. The others are the Write Ahead Log file (-wal) and the Shared Memory file (-shm). They are used by the underlying SQLite system to improve performance, and contain the latest changes to the main database until a checkpoint is done. You can find more information in the SQLite docs.
Your original database is ImageDatabase i.e name of database you give at the time of creation.
you can copy database and check the contain from here
upload your database in above link and you can verify it.

Change Database structure Sqlite

I am working on an android application on android studio, and I am using a sqlite database. The thing is, I want to change the structure of it, so do I just have to change it from DB Browser for SQLite, or I need to change it somewhere else ?
Because the code I am working on isn't mine, and I am just starting to lear android developement
An option is to change the internal structure of the database file from either DB Browser or command line on your computer and then copy it to your phone's storage when the App is running.
If you don't know the steps:
Step 1: Create a new database file from either command line or SQLite DB Browser with your required structure.
Step 2: Place the file in Assest directory in your Project folder. (Assest directory will be in the same folder as the 'res' and 'java' directories are)
Step 3: On Activity Start event, copy this empty database from Asset directory to your database directory which is generally located at /data/data/your.package/databases
Also you can query ALTER TABLE to add columns (as suggested in comments).
This explains the syntax for ALTER TABLE. It also explains other methods for implementing Schema Changes.

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.

SQLite on Google App Engine

Is it possible to use SQLite as a relational database from Google App Engine? (Java) I need read/write access to it from the app itself.
Also, I am using Quercus for PHP, and if what I am asking for is possible, I can handle storing the database myself.
No, it is not possible. This would require write access to the filesystem, which App Engine does not allow.
SQL database support (MySQL like) is planned, but no release data has been given. For now, use the datastore.
I know it's a super old question and nothing concerning read-only properties of App Engine has changed since then... But actually you can use sqlite on Google App Engine. There is a writable /tmp directory (https://cloud.google.com/appengine/docs/standard/java-gen2/using-temp-files). If your app on startup first copies the db.sqlite3 file to /tmp/db.sqlite3 and references this path as database path, it will work.
The following problems are connected with this approach:
This directory is "in-memory". So if you want to use really large sqlite file, you may face problems with RAM.
Each node of the app gets its own copy of the database. If you save something on one node, these changes will not be seen by other nodes. And the new data will be lost if the app scales to 0.

Categories

Resources