Change Database structure Sqlite - java

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.

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.

Android Studio (Database From Asset Folder)

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?

Create Jar file with IntelliJ IDEA that has mysql database

I want to create (export) my application into a Jar file to be portable.
How can i put my database contents with jar file?
For e.g for pictures, i put pictures folder beside my jar file, and it shows pictures correctly.
UPDATE
A peace of code to connect to database:
connection = DriverManager.getConnection("jdbc:mysql://localhost/Library", "root", "1234");
If you want to distribute a copy of your database with each copy of your application, I think using MySQL will be a bit complicated. You may want to look into using a database system designed to be embedded, such as SQLite, instead. A complete SQLite database is a single text file - you'd simply distribute your one mydatabase.db file along with the jar. See the examples at the above link.
There are two approaches you could use:
Approach 1
Do you really need to use database? If not, store your data on files in file system, that way you can easily export it with data.
Approach 2
Bundle the mysql installation directory in your jar / installer. Write a scripts which starts up both MySQL server and you application.

how to include mysql db inside eclipse project

I have a dynamic web java project, which needs to talk to a database
i want to include the created database file inside the project, so that i can access the data inside and the db isnt on some server
is it possible to do that? if so, how ?
For eclipse, open view Data Source Explorer and add the database.

Java app with embedded DERBY DB

I am trying for a while to make executable JAVA application having embedded DB (derby DB), but facing some problems, and need your valuable help.
Namely, I am using Eclipse as environment.
I export Java app to RUNNABLE JAR file, and it works fine on my desktop machine.
The idea is to make EXE doubleclick icon and send it to another machine which have no JAVA background/environment....so point is to send it to another user who will just get exe file, double click it and work with it.
The DB is not only readable, since application is inserting data in tables.
So, it works fine on my machine, but when I send the same JAR file to another machine, I get error:
"Schema TEST does not exist"
I can see application but without any data, like there is no connection with DB. So, it is useless.
Even I use JSmooth, Install4j.... to convert JAR to exe file, I get the same error.
So, first I have to make JAR file working on another machine.
Seems to me, I am doing something wrong with DB files.
Please let me know what info u need more from my side, and let me know how I can do this.
If the application intends to read AND WRITE data when it is running, then it can't be entirely contained in a JAR file, because you can't put an updatable Derby database in a JAR file. You'll need to have some "installation procedure", perhaps some logic that you run the first time your application is double-clicked by the user, that (a) finds a suitable location for the Derby database on the user's machine, (b) creates the database and defines all the tables, views, etc, (c) loads any initial data.
Then, on subsequent runs of the application, it will be able to re-open the database and continue using it.

Categories

Resources