Android: add some rows to sqlite database not working

I insert one row into the database using the following method for an android project.

myDB.execSQL("INSERT INTO "
 + Buss
 + " (BussName, RouteName)"
 + " VALUES ('buss1', 'buss2');");

It works great. And I see this link Insert multiple rows into sqlite database . and I try this method (insert multiple lines) 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?

+4
source share
2 answers

You need to call a separate insert statement for each row.

For performance reasons, you can group every few calls (say ~ 20) into one transaction:

myDb.beginTransaction();
   for(<your loop definition>){ myDb.execSQL(<your insert statement>) }
myDb.setTransactionSuccessful();
myDb.endTransaction();

, , . , "" . , .

.

, SQL - : SQlite Android?

+8

SQLite 3.7.11 , jellybean kitkat Sqlite 3.7.11

+5

Source: https://habr.com/ru/post/1531949/


All Articles