1

i have script for insert multiple rows :

protected static final String INSERT_NAME_LIST1 = "insert into Table_Name(name1,name2) VALUES (1,'aa'),(1,'bb'),(1,'cc');";

But i have error :

06-21 14:15:31.155: E/AndroidRuntime(12798): Caused by: android.database.sqlite.SQLiteException: near "','": syntax error: insert into Table_Name(name1,name2) VALUES (1,'aa')',' (1,'bb')',' (1,'cc');

please help me, how to fixed error ???

Kazekage Gaara
  • 14,972
  • 14
  • 61
  • 108

2 Answers2

2

you can do it easily in noramally in SQL but in SQLite I think can try this in which it recast into sqlite as:

Is it possible to insert multiple rows at a time in an SQLite database?

Community
  • 1
  • 1
Dheeresh Singh
  • 15,643
  • 3
  • 38
  • 36
1

I think you can only have one set on values in the statement

protected static final String INSERT_NAME_LIST1 = "insert into Table_Name(name1,name2) VALUES (1,'aa');";

Multiple inserts can be done with a union

 INSERT INTO 'Table_Name'
 SELECT 1 AS 'name1', 'a' AS 'name2'
 UNION SELECT 2, 'b'
 UNION SELECT 3, 'c'
 UNION SELECT 4, 'd'
tsukimi
  • 1,605
  • 2
  • 21
  • 36