插入的Andr​​oid 4.0.3源码的错误 [英] Insert Error SqLite in Android 4.0.3

查看:158
本文介绍了插入的Andr​​oid 4.0.3源码的错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的平板电脑的Andr​​oid 4.0.3v一个SQLite问题;

i have a Sqlite problem in my tablet Android 4.0.3v;

错误:

07-28 14:28:18.495    6995-7125/com.titan.tablet E/AndroidRuntime﹕ FATAL EXCEPTION: Thread-544
android.database.sqlite.SQLiteException: near ",": syntax error: , while compiling: INSERT INTO  tb_ingrediente  ( ID_INGREDIENTE ,  DESCRICAO ,  ATIVO ,  UNIDADE ) VALUES
(1, 'CARNE', 1, 'UN'),
(2, 'QUEIJO',  1, 'UN'),
(3, 'PRESUNTO',  1, 'UN'),
(4, 'OVO',  1, 'UN'),
(5, 'FARINHA', 1, 'UN'),
(6, 'SALADA',  1, 'UN'),
(7, 'CEBOLA',  1, 'UN'),
(8, 'COCA-COLA 2L',  1, 'UN'),
(9, 'ÓLEO', 1, 'UN'),
(10, 'TOMATE', 1, 'UN');

在我的Andr​​oid手机4.1.2本problema不会发生。

In my Cellphone Android 4.1.2 this problema not happen.

插入code:

 db.execSQL("INSERT INTO  tb_ingrediente  ( ID_INGREDIENTE ,  DESCRICAO ,  ATIVO ,  UNIDADE ) VALUES\n" +
                "(1, 'CARNE', 1, 'UN'),\n" +
                "(2, 'QUEIJO',  1, 'UN'),\n" +
                "(3, 'PRESUNTO',  1, 'UN'),\n" +
                "(4, 'OVO',  1, 'UN'),\n" +
                "(5, 'FARINHA', 1, 'UN'),\n" +
                "(6, 'SALADA',  1, 'UN'),\n" +
                "(7, 'CEBOLA',  1, 'UN'),\n" +
                "(8, 'COCA-COLA 2L',  1, 'UN'),\n" +
                "(9, 'ÓLEO', 1, 'UN'),\n" +
                "(10, 'TOMATE', 1, 'UN');" );

有人能帮助我发现为什么错误只发生在安卓4.0.3?

Could someone help me discover why the error only occurs in android 4.0.3?

推荐答案

当插入值,只能插入一次一个记录。有没有办法用一个语句大众插入多条记录。如果你打算将使得大量的插入,你可以缓存所有插入语句和提交他们一下子使过程更快。

When inserting values, you can only insert a single record at a time. There's no way to mass-insert multiple records with a single statement. If you're going to be making a large number of inserts, you can cache all of your insert statements and commit them all at once to make the process faster.

    db.beginTransaction();
    try {
        db.execSQL("delete from " + Table);
        int Xtra = cols.getColumnCount() - tabledata.get(0).size();
        for (ArrayList<String> item : tabledata) {
            for (int a=0;a<Xtra;a++) {item.add("");}
            db.execSQL("insert into " + Table + " values " + rowValues(item) + ";");
        }
        db.setTransactionSuccessful();
    } catch (Exception e) {
        Log.e("DBWrapper", "insertArrayList error: " + e.getMessage());
    } finally {
        db.endTransaction();
    }

这篇关于插入的Andr​​oid 4.0.3源码的错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆