sqlite android中的多个insert语句

时间:2014-09-05 13:40:47

标签: android sqlite insert bulkinsert

大家好我有多个插入语句的问题,我需要插入很多记录。我已经用这种方式写了但是记录没有被插入" userbill"桌子。帮我??

..这是代码:

    SQLiteDatabase db = mySQLiteHelper.getWritableDatabase();
    String sql = "insert into userbill (billid, userid, date, amount, bill_status) values (?, ?, ?, ?, ?)";

    db.beginTransaction();
    SQLiteStatement st = db.compileStatement(sql);

    try{
        for(int i=0;i<Userid.length;i++)
        {

                st.bindLong(1, billid);
                st.bindString(2, Userid[i]);
                st.bindString(3, due_date);
                st.bindDouble(4, amount/Userid.length);
                st.bindString(5, "Due");

                long entryID = st.executeInsert();
                st.clearBindings();
        }

       db.setTransactionSuccessful();
    }
    catch(Exception e)
    {
        //e.printStackTrace();
        Log.e("MYAPP", "exception", e);
    }
    finally
    {
        db.endTransaction();
    }
    db.close(); 

logcat的:

09-05 13:12:48.610:D / dalvikvm(7982):GC_FOR_ALLOC释放314K,10%免费5030K / 5568K,暂停17ms,总计18ms

09-05 13:12:48.610:I / dalvikvm-heap(7982):将堆(frag case)增长到6.181MB,用于1127532字节分配

09-05 13:12:48.614:D / dalvikvm(7982):GC_FOR_ALLOC释放2K,9%免费6129K / 6672K,暂停5ms,总计5ms

09-05 13:12:48.710:W / EGL_genymotion(7982):eglSurfaceAttrib未实现

09-05 13:12:57.014:I / SQLiteConnectionPool(7982):/data/data/com.perfect12.app2maintain/databases/AMTDB的连接池已关闭,但仍有1个连接正在使用中。当他们被释放回游泳池时,他们将被关闭。

09-05 13:12:57.286:W / EGL_genymotion(7982):eglSurfaceAttrib未实现

1 个答案:

答案 0 :(得分:5)

你写

db.beginTransaction();

两次代码。