本文介绍了安卓SQLiteException:近",":语法错误:在编制INSERT的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图将值插入表

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及更高版本,它工作得很好。

Error occurs on Android 4.0.4 HTC Sense 3.6.I tested on multiple devices runnin on Android 4.2 and higher and it works fine.

有谁知道是什么问题?

推荐答案

多值语法是在SQLite 3.7 0.11

The multi-values syntax was introduced in sqlite version 3.7.11

sqlite的版本3.7.11仅在安卓4.1及以上

分裂您插入到不同的刀片,一排的时间。

Split your inserts into separate inserts, one row at a time.

这篇关于安卓SQLiteException:近",":语法错误:在编制INSERT的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-11 01:39