I am Inserting single row into database using following method for android project.
myDB.execSQL("INSERT INTO "
+ Buss
+ " (BussName, RouteName)"
+ " VALUES ('buss1', 'buss2');");
It work fine. And I see this link Inserting multiple rows in sqlite database. and I try this method(insert multiple rows) in my android project, but It does not work.
myDB.execSQL("INSERT INTO "
+ Buss
+ " (BussName, RouteName)"
+ " VALUES ('buss1', 'buss2'),('buss1', 'buss2'),('buss1', 'buss2');");
How to do it?
If you want to inset the data manually(fully graphical) do the following: Go to the DDMS perspective. File explorer (tab-menu) Locate your db (/data/data/com.
SQLite Database is an open-source database provided in Android which is used to store data inside the user's device in the form of a Text file. We can perform so many operations on this data such as adding new data, updating, reading, and deleting this data.
The theoretical maximum number of rows in a table is 264 (18446744073709551616 or about 1.8e+19). This limit is unreachable since the maximum database size of 281 terabytes will be reached first.
You need to call separate insert statement for each row.
For performance reason you can group every few calls (let say ~20) into one transaction:
myDb.beginTransaction();
for(<your loop definition>){ myDb.execSQL(<your insert statement>) }
myDb.setTransactionSuccessful();
myDb.endTransaction();
The main idea is to not write physical database file on every inserted row, but every few rows. On other had as long as inserted data is not persisted on "drive" it's in the memory. For small data sets you can just start transaction, make all inserts and end transaction in one block.
For bigger data you should make your transactions smaller.
Using prepared statement instead of standard statement is also a good idea, as the SQL interpreter needs to parse query only once - more information can be found here: How do I use prepared statements in SQlite in Android?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With