Does anyone know how to import a downloaded sql file to the android database via room?
I have a .sql file in android phone which is exported from mysql database. I want to import the .sql file to the android sql database.
I try to use the room of android JetPack. I check the official site:https://developer.android.google.cn/training/data-storage/room/creating-views
But dont find a way to do that.
The content in my .sql file is like:
DELETE FROM NewsInfo WHERE id = '20210524210624';
INSERT INTO NewsInfo VALUES ('20210524210624','2','aaa','bbb',3,'','','','en','push','2021-05-24 21:06:24');
So does anyone know how to import a downloaded sql file to the room on Android?
Thanks in advance
The best way I know of is to retrieve the actual db object from Room that has the execSQL() function.
And stream in the .sql file for each line db.execSQL(line);
(edit) If I knew this information wasn't readily available I would have posted the example, but I actually couldn't find it myself.
RoomDatabase database = ...
SupportSQLiteDatabase db = database.getOpenHelper().getWritableDatabase();
db.beginTransaction();
db.execSQL(line);
db.endTransaction();
You can simply call the query method on your Database instance.
appDatabase.query("YOUR INSERT QUERY")
So call the above method for each query you get in the .sql file.
Related
For a schoolproject I have converted a php database from MySQL to MySQLi to use it in my android application.
I've looked into creating a android database using head's first book on android (2017) and according to that I need to manually create and insert every record in the database, but I already have all the data needed and one table even has 113 entries that need to be inserted.
Isn't there a way for me to import the existing database without completely creating it all over again?
Use SQLite browser , hope it helps .
Export SQL file from MySql and put it into assets folder. Read sql file from assets, use 'db.execSQL' method to create and insert all records of sql file. Some of the 'keywords' are working in SQLite of MySql so firstly remove these keywords from file.
I'm developing an android application which use SQLite database.
The question is: can I import an external script (i.e. script.sql) which can upgrade the structure of SLQLite database in my application?
Why not, SQLiteDatabase class has "rawQuery" method which can perfrom any valid sql commands. So you only need to create the database, read your script from file and feed it to SQLiteDatabase instance
I'am developing an application which uses sqlite for autocomplete textview. The database has more than 8000 records. Creating a database can be done with a query in onCreate(). But how do i create a database with 8000+ records in it. writing insert query for 8000 records sounds worst to me.
What's the best way to create a database with 8000+ records in it. Is there any way like dumping sql file like how we do in mysql.
Instead, you should put your database with a table (having 8000 records) inside the Assets folder and write a logic to Copy existing database inside your android app.
Check links:
https://stackoverflow.com/a/6541043/379693
Ship an application with a database
What ever approach you conduct but do it in an SQLite Transaction because it will maintain a single Journal (db cache) file for inserting all the records in one go. It will really speed up things a lot.
If you have the .sql file you may import it in phpMyadmin....
Just go to PHPMyadmin URL...
create an empty database....
click on import...
Browse the sql file
click on Go...
That's it
I have to use remote MySQL database information in my Android application.
Is there a way that I can Translate MySQL data to SQLite format and store them in the SQLite DB to access by the mobile application.
Also I need to update the SQLite DB content when a modification happen to MySql data.
That I have decided to do when application loads, to check any modification happened and to change the SQLite DB Accordingly. Is this possible.
Any sample coding/ Idea/Link is highly appreciated.
Thanks in advance
Can you use mysqldump to export the information, for later import into SQLite? mysqldump will export data you specify, and save it into a file containing a bunch of SQL statements to rebuild the data.
So for example, if you run the dump on a schema with 3 tables and a bunch of rows in each, you end up with a .sql file with commands to build those 3 tables and then enter all the rows. The SQL can be used to import into another MySQL database or most other SQL databases.
mysqldump
I would think you could create a batch script of some sort to run the dump command, then use SQLite to pick up and run the .sql file.
I have the data in the android(Sqlite Database).How to transfer this database data's to the System Database( like Access or SQL Server).After Transfer this data's i have to use the data in the System.I am new to android. Can anyone help me.
Note:
If the android device have the Database db1.I wish to use the db1 data in the Desktop Application .
You can copy the database file to the desktop, and then open it there with SQLite. You could then export the data to CSV file, and import this one in the database of your choice.
The db file is present in "/data/app/" Your Application Package directory "/databases/" Your DB File.
Copy the file from this location and use the steps provided by Thomas Mueller.