这个问题已经在这里有了答案: > Is it possible to insert multiple rows at a time in an SQLite database? 24个
我正在尝试将值插入表
public class DatabaseHandler extends SQLiteOpenHelper {
private final static String INSERT_INTO_COUNTRIES = "INSERT INTO " + TABLE_COUNTRIES
+ " VALUES";
@Override
public void onCreate(SQLiteDatabase db) {
final String countries = "('1','Andorra','93','flag_andorra','AND'),
('2','Austria','43','flag_flag_austria','AUT')";
String query = INSERT_INTO_COUNTRIES + countries + ";";
db.execSQL(query);
}
}
并得到以下错误:
android.database.sqlite.SQLiteException: near ",": syntax error: , while compiling: INSERT INTO cardberry_countries VALUES('1','Andorra','93','flag_andorra','AND'),('2','Austria','43','flag_flag_austria','AUT');
在Android 4.0.4 HTC Sense 3.6上发生错误.
我在Android 4.2及更高版本上运行的多种设备上进行了测试,并且工作正常.
有人知道出什么问题吗?
解决方法:
在sqlite版本3.7.11中引入了多值语法
Sqlite version 3.7.11 is only in Android 4.1 and up.
将您的插入片段拆分为单独的插入片段,一次插入一行.
【说明】:本文章由站长整理发布,文章内容不代表本站观点,如文中有侵权行为,请与本站客服联系(QQ:254677821)!