我有插入多行的脚本:
protected static final String INSERT_NAME_LIST1 = "insert into Table_Name(name1,name2) VALUES (1,'aa'),(1,'bb'),(1,'cc');";
但我有错误:
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');
请帮助我,如何修复错误???
答案 0 :(得分:2)
你可以在SQL中非常容易地做到这一点但在SQLite中我认为可以尝试将其重新编写为sqlite:
Is it possible to insert multiple rows at a time in an SQLite database?
答案 1 :(得分:1)
我认为你只能在声明
中设置一个值protected static final String INSERT_NAME_LIST1 = "insert into Table_Name(name1,name2) VALUES (1,'aa');";
可以使用联合
完成多次插入 INSERT INTO 'Table_Name'
SELECT 1 AS 'name1', 'a' AS 'name2'
UNION SELECT 2, 'b'
UNION SELECT 3, 'c'
UNION SELECT 4, 'd'